views:

39

answers:

1

Hi

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

A: 

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>.

Stephen Cleary