Entity Framework and SQL Server 2012 Paging

做~自己de王妃 提交于 2019-12-08 16:05:03

问题


SQL Server 2012 introduces a more efficient mechanism for paging using FETCH and OFFSET which could have a big impact on performance of apps which use a lot of paging. Does Entity Framework 5 support this? So if Im using EF to page using Take + Skip will the LINQ queries be translated into the new 2012 TSQL if EF is targeting SQL Server 2012?


回答1:


EF 5 doesn't support this feature - actually I think none of SQL Serve 2012 features is available in EF. You can vote for this feature on Data UserVoice to move it up in ADO.NET team product backlog.




回答2:


As @Ladislav said, EF 5 doesn't support OFFSET & FETCH. With that said, I wanted to add a bit of perspective. I don't think it should matter much.

When you buy into an ORM like Entity Framework, you're out sourcing your query generation (for perfectly valid reasons). Whether EF uses the 'older' CTE style query with Row_Number() or the newer Fetch / Offset is an implementation detail. Microsoft could update the EF code at any point and change the query generation to use one or the other.

If you want control over the query generation, you either:

  • Use EF's 'stored procedure mapping' ability
  • Use stored procedures directly with EF (something I do quite often)
  • write the ADO/SQL yourself, or
  • use a more limited micro-orm like massive/PetaPoco

So does it matter?

Well, to a developer writing queries the new syntax is going to be a welcome relief. On the other hand, it doesn't appear that there is a real performance difference between the old CTE method and the new syntax. So from EF's perspective -- not really. We incur a significant overhead using EF, the method of paging probably won't be your break point.



来源:https://stackoverflow.com/questions/10245221/entity-framework-and-sql-server-2012-paging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!