Why is Linq for Entities so slow that the first time it referenced

using Entity Framework 4.0, it seems that the first time an operation is performed (read or write) in the context of an entity object, it takes magnatude orders longer than the second time. For example, a query for the first time may take 10 seconds (yes seconds) and a second time .1 seconds.

I assume that the first time the context object is built, it should build some kind of scene data structures? Does the EDMX file parse (I thought it would be done at compile time?)

+3
source share
3 answers

It creates views that will be cached on subsequent calls.

, :

http://www.dotnetspark.com/kb/3706-optimizing-performance.aspx

+5

EF Entity Data (EDM) , , , .

+1

Perhaps you have a problem with the DB table with which your query is being executed. So, the first time you run EF, it compiles your query, creates an execution plan, etc. Therefore, when you use the second time, DB uses the cached version of your query. Try adding indexes to your table and see if that helps.

0
source

All Articles