Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.1 query takes too long (5 seconds) to complete

I have DbContext (called "MyContext") with about 100 DbSets within it.

Among the domain classes, I have a Document class with 10 direct subclasses (like PurchaseOrder, RequestForQuotation etc). The heirarchy is mapped with a TPT strategy. That is, in my database, there is a Document table, with other tables like PurchaseOrder, RequestForQuotation for the subclasses.

When I do a query like:

Document document = myContext.Documents.First();

the query took 5 seconds, no matter whether it's the first time I run it or subsequently.

A query like:

Document document = myContext.Documents.Where(o => o.ID == 2);

also took as long.

Is this an issue with EF4.1 (if so, will EF4.2 help) or is this an issue with the query codes?

like image 354
swirlobt Avatar asked Dec 28 '22 11:12

swirlobt


1 Answers

Did you try using SQL Profile to see what is actually sent to the DB? It could be that you have too many joins on your Document that are not set to lazy load, and so the query has to do all the joins in one go, bringing back too many columns. Try to send a simple query with just one return column.

like image 133
Claiton Lovato Avatar answered May 08 '23 02:05

Claiton Lovato