[英]How to use SQL Server OFFSET & FETCH FIRST with Entity Framework 5?
Is OFFSET
& FETCH FIRST
keywords, which are introduced in SQL Server 2012 are supported in EntityFramework 5
and Linq to SQL? 是否在EntityFramework 5
和Linq to SQL中支持SQL Server 2012中引入的OFFSET
和FETCH FIRST
关键字?
It's showing 50% performance improvement when using SELECT * FROM tables ORDER BY stime DESC OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY
instead of var a= db.table.Skip(0).Take(10);
当使用SELECT * FROM tables ORDER BY stime DESC OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY
时,它表现出50%的性能提升SELECT * FROM tables ORDER BY stime DESC OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY
而不是var a= db.table.Skip(0).Take(10);
Short Answer is No, it is not supported in EF5, but Version 6.1.2 of Entity Framework has just been released, as noted on the ADO.NET blog . 简短答案是否定的,EF5不支持它,但实体框架的6.1.2版刚刚发布,如ADO.NET博客中所述 。 One of the new features in 6.1.2 is support for the OFFSET..FETCH SQL Server 2012+ paging syntax. 6.1.2中的一个新功能是支持OFFSET..FETCH SQL Server 2012+分页语法。
When you buy into an ORM like Entity Framework, you're out sourcing your query generation (for perfectly valid reasons). 当您购买像Entity Framework这样的ORM时,您需要获取查询生成(出于完全正当的理由)。 Whether EF uses the 'older' CTE style query with Row_Number() or the newer Fetch / Offset is an implementation detail. EF是否将“旧”CTE样式查询与Row_Number()或较新的Fetch / Offset一起使用是一个实现细节。 Microsoft could update the EF code at any point and change the query generation to use one or the other. Microsoft可以随时更新EF代码,并将查询生成更改为使用其中一个。 Reference 参考
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? 使用EF的'存储过程映射'能力直接使用存储过程与EF(我经常做的事情)自己编写ADO / SQL,或者使用更有限的微观orm像/ PetaPoco那么重要吗?
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. 另一方面,旧的CTE方法和新语法之间似乎没有真正的性能差异。 So from EF's perspective -- not really. 所以从EF的角度来看 - 不是真的。 We incur a significant overhead using EF, the method of paging probably won't be your break point. 使用EF会产生很大的开销,寻呼方法可能不会是你的突破点。 Refrance Refrance
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.