Skip to content Skip to sidebar Skip to footer

(ef 4.0 Vs A Normal Sql) Improve Execution Time In Linq

When I execute this SQL statement, it takes absolutely no time to run: select * from [user] left join licence on [user].userID = licence.UserID left join licenceProducts on licence

Solution 1:

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.

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.

See also http://www.mssqltips.com/sqlservertip/1990/how-to-use-sql-server-views-with-the-entity-framework/.

Post a Comment for "(ef 4.0 Vs A Normal Sql) Improve Execution Time In Linq"