EF4 and ASP.Net MVC LINQ - Join Two Entities into One IQueryable Complex Type

asp.net-mvc entity-framework iqueryable linq

Question

I have code that looks like:

 var entityX = this._xService.GetAll();
 var entityY = this._yService.GetAll();

They are both given back as IEnumerable types. I must inner link the two to create a class like JoinedList, which must be IQueryable.

Please advise on LINQ-based approaches of doing this.

Thank You

1
0
11/17/2013 5:31:51 PM

Accepted Answer

LINQ to Objects makes a great adhesive:

var entityX = this._xService.GetAll();
var entityY = this._yService.GetAll();
var joinedSequence = from x in entityX
                     join y in entityY on x.Key equals y.Key
                     select new { x, y };
var joinedQueryable = joinedSequence.AsQueryable();

Really, you shouldn't have done that last thing;IQueryable<T> is not required since LINQ to Objects functions perfectly withIEnumerable<T> .

2
7/3/2010 1:47:00 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow