Implement a LINQ to Entities method without support

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

Is there a way to implement some of these methods by hand? Or should I wait for the next EF release?

I especially need 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 like this:

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

+2


a source to share


2 answers


LINQ to Entities (and other LINQ-based implementations IQueryable<T>

) work by translating expression trees into the target system (in LINQ to Entities: SQL).

To support additional operators, changes need to be made to this level of translation, which is at the heart of vendor implementation.



Given that SQL is oriented toward orientation, I doubt any of the query operators that support an indexed delegate tree or expression tree will be supported.

+2


a source


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 do additional filtering, do so before executing ToList ():

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

      

If this is not a solution, please clarify what you want to achieve. An example with data or SQL query would be nice.

+2


a source







All Articles