且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(EF 4.0与普通SQL相比)缩短了Linq的执行时间

更新时间:2023-02-06 23:05:28

直接在SQL中编写查询通常比在LINQ中编写表达式要高效得多,后者必须将其转换为次优" SQL.

Writing queries directly in SQL is almost always way more efficient than writing expressions in LINQ which must then be translated into "sub-optimal" SQL.

您可以做的就是简单地创建一个包含查询的VIEW,然后将该VIEW映射到Entity Framework中的Entity,然后查询该Entity-这将只执行VIEW在SQL Server中.

What you could do is simply create a VIEW that contains your query, then map that VIEW to an Entity in Entity Framework, then query that Entity -- which will just execute the VIEW in SQL Server.

另请参见 http://www.mssqltips.com/sqlservertip/1990/how-to-use-sql-server-views-with-the-entity-framework/.