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 like:

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

Both are returned as IEnumerable types. I need to inner join the two into a something like a JoinedList class that has to be IQueryable.

I'm looking for ways to do this please using LINQ.

Many Thanks

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

Accepted Answer

LINQ to Objects is excellent glue:

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();

You shouldn't really need that last step; IQueryable<T> is unnecessary because LINQ to Objects works just fine with IEnumerable<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