I've taken over a project with Entity Framework. The code seems to be good layered and done with good structure. The problem is as I've seen many times with Entity Framework, that they used lazy loading alot. The problems don't apear until the db got some data and the sql queries just peaks.
The solution take a great use of keeping the repositories small and just get one level of data and as I worked with some of the biggest performance issues, the most common issue is often resolved by adding specific function to the repository that loads the nested entities and use some dynamic queries.
i.e. GetCustomerWithOrderData that includes orders, order rows etc.
Sometimes I have to merge two queries by first get Customer (with included relations) and then get Orders (with included) and map them together by linq.
The queries is far more complex then the examples and the lazy loading could be in business layer, controllers or views so there is wuite alot to trace to resolve.
But I feel that the code is quite large and I have a hard time finding the future problems. What I now need is a good way to track when there is lazy loading, and also be able to tell what objects that need to be loaded on a specific call.
The best would be if I could track a specific action call, and get what sql that executes, how many times, loadtime etc.
The solution is build with MVC 3 and EF4, is there any performance to gain by upgrading to newer EF?