Question

Is there a recommended maximum amount of .Include statements to use in an Entity Framework query.

I think i read somewhere Microsoft recommends no more than three but I cant find that source.

Thanks in advance.

Was it helpful?

Solution

See performance considerations for entity framework http://msdn.microsoft.com/en-us/data/hh949853.aspx (p 8.2.2) :

It takes a relatively long time for a query with multiple Include statements in it to go through our internal plan compiler to produce the store command. The majority of this time is spent trying to optimize the resulting query. The generated store command will contain an Outer Join or Union for each Include, depending on your mapping. Queries like this will bring in large connected graphs from your database in a single payload, which will acerbate any bandwidth issues, especially when there is a lot of redundancy in the payload (i.e. with multiple levels of Include to traverse associations in the one-to-many direction).

I suggest to use SQL Profiler or EF Profiler (f.e. EFProf) which can help with performance issues

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top