简体   繁体   English

如何在Entity Framework 5中使用SQL Server OFFSET&FETCH FIRST?

[英]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中引入的OFFSETFETCH 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.

相关问题 如何告诉Entity Framework首先在代码中使用SQL Server Compact? - How do I tell Entity Framework to use SQL Server Compact in code first? 如何使用实体框架生成与SQL Server兼容的数据库(代码优先) - How to generate a SQL Server compatible database with Entity Framework (code first) 如何让 Entity Framework Code First 使用 SQL Azure DB? - How to make Entity Framework Code First use the SQL Azure DB? 实体框架数据库优先-SQL Server - Entity Framework database-first with SQL Server 外部SQL服务器上的实体框架代码优先 - Entity Framework Code First on external SQL server 在本地使用SQL Server CE和在生产实体框架代码上使用SQL Server 2008? - Use SQL Server CE Locally and SQL Server 2008 on Production Entity Framework Code First? 如何在Xamarin形式的SQL Server中使用Entity Framework Core? - How to use Entity Framework Core with SQL Server in Xamarin Forms? 在 UWP 中将实体框架与 SQL Server 结合使用 - Use Entity Framework with SQL Server in UWP 如果我们使用具有代码优先方法的Entity框架,是否可以在给定路径上创建数据库(Sql Server compact)? - Is possible to create a database (Sql Server compact) on a given path if we use Entity framework with code-first approach? SQL Server 2017 OFFSET + FETCH - 如何知道达到最后结果 - SQL Server 2017 OFFSET + FETCH - How to know last result was reached
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM