开发者

Entity Framework 4: C# code to translate Microsoft SQL 2005/2008 row_number to a field?

Is .Skip().Take() the only way to get paging in Entity Framework? Is th开发者_如何学运维ere some way to select the row number in the output so I could use Where( p => p.row > 9 && p.row <21)?

select top 100 ROW_NUMBER() over (order by ID) as row, * 
from myTable

I would think the ROW_Number() field must exist in the generated SQL for it to know what rows to skip and take.

Of course, I could get around this by creating separate SQL views with that field, or I could specify the exact SQL to EF, but I really want to use the Linq Expressions.


Linq to entities can work only with fields which are mapped to entities. So if you build SQL view and map column containing row_number to row field in your entity, you will be able to do that otherwise not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜