开发者

Implement LINQ to Entities unsupported method

开发者 https://www.devze.com 2022-12-26 10:09 出处:网络
LINQ to Entities has many LINQ methods marked as \"Unsupported\" (http://msdn.microsoft.com/en-us/library开发者_如何学C/bb738550.aspx).

LINQ to Entities has many LINQ methods marked as "Unsupported" (http://msdn.microsoft.com/en-us/library开发者_如何学C/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});


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消