views:

47

answers:

2

Hi!

LINQ to Entities has many LINQ methods marked as "Unsupported" (http://msdn.microsoft.com/en-us/library/bb738550.aspx).

Is any way to implement some of these methods by hands? Or I should wait next release of EF?

I'm especially needing this method:

IQueryable<TResult> Select<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, int, TResult>> selector)

Thanks

UPD: For example I want to use select in this way:

var usersWithRowNumbers = allUsers.Select((u, index) => new {UserID = u.UserID, Index = index});

A: 

LINQ to Entities (and other LINQ implementations based in IQueryable<T>) work by translating expression trees into the target system (in LINQ to Entities: SQL).

To support additional operators, changes would have to be made in that translation layer, which is at the very core of the providers implementation.

Given SQL is set orientated, I doubt any of the query operators which support a delegate or expression tree taking an index will ever be supported.

Richard
+2  A: 

Something like that?

allUsers.Select(u => new {UserID = u.UserID}).ToList().Select((u, index) => new {UserID = u.UserID, Index = index})

EDIT

If you want to make additional filtering, make it before executing ToList():

allUsers.Select(u => new {UserID = u.UserID}).AdditionalFilters().ToList().Select((u, index) => new {UserID = u.UserID, Index = index})

If it is not solution then please, be more precise with what you want to achieve. Example with data or sql query would be good.

LukLed
Yes, something like that. But for LINQ to Entities.
Dan
@Dan: It works with Linq to entities.
LukLed
Would AsEnumerable() instead of ToList() be enough to make the second Select possible? If so, it would avoid storing all the IDs in memory at once, in case there are lots of them.
stevemegson
@LukLed: But it isn't Linq to entities. I cannot store all items in memory.
Dan
@stevemegson, yes, `AsEnumerable()` will work.
Craig Stuntz