Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • I get the performance penalty even if I'm not filtering. context.LoanApplications is always faster than context.LoanApplications.Include("Solicitors"), even if that means goint to the database 20 times to get each child solicitor when the navigational property is called Commented Apr 3, 2013 at 4:07
  • maybe I was not clear in what I meant. the DbContext caches the entities, so if you have the Solicitors in the cache already, when you call the navigation property on applications it will get them from the cache instead of the database. The code I suggested was to optimize caching the solicitors so you are only fetching the ones you'll actually need. Commented Apr 3, 2013 at 4:16
  • Gave it a try, gained some speed on the query, but the lazy load option is still faster. Do you have any idea what the best practice in this scenario is? Commented Apr 3, 2013 at 4:22
  • If this is a query you use all the time, and the actual data (columns) you use from both entities is small, you could consider using SqlQuery<CustomClassForReturnedColumns>("Your raw sql query here"). That would be the optimal solution performance wise. Commented Apr 3, 2013 at 4:31
  • No, I actually have a repository pattern in place and this same query is used by many other entities (I simplified the query for the question). Doing a raw sql call would defeat the purpose of using the Entity Framework and the patterns for reusable code that I have in place. Commented Apr 3, 2013 at 15:16