Asp.net Entity Framework and generated SQL issue

I have a problem with the following Linq query using Entity Framework:

from o in ctx.Entity
where o.EntityID = entityid
select o;

      

Simple enough? Well, the "Entity" set is the parent class of many other classes. The generated SQL for this simple query is about 20 thousand characters with many "case" and "union". In addition to taking some time to compile the query, it also takes some time to complete.

So how can I improve the SQL generated by the framework in the case of queries using legacy classes? Or what other method can I use to avoid this problem?

AD

+1


source to share


1 answer


The reason this is happening has to do with the Entity's relationships with other tables in your database. To shorten this, you need to read about how to better control the explicit / lazy loading of links that EF does for you.

http://blogs.msdn.com/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx



No posts like this would be complete without a plugin for nhibernate, which is more powerful / reliable / efficient / and easier to use ;-), but hopefully this link will help you

+1


source







All Articles