Entity Framework Productivity Checklist

I am developing a project using Entity Framework 4. Having about 50 objects, basically all the tables are related to the user table. Searching for a user a little more time to return results. In the user table, I deleted the navigation properties, even if you have more time. The web page mainly provides performance recommendations for any given scenario / problem. Is there a common checklist to improve Entity Frame performance?

Find user as dynamically as follows

var searchPredication = (from user in entities.Users where ((searchKeyword == "") || (searchField != "" && searchKeyword != "" && searchField == "BarCode" && user.BarCode == searchKeyword)|| (searchField == "LastName" && user.LastName == searchKeyword) || (searchField == "FirstName" && user.FirstName == searchKeyword))) && !user.IsDeleted select user).FirstOrDefault(); 

And also I need to provide more information about general performance management in EF.

+4
source share
1 answer

Actually there is no β€œchecklist”, but here are some tips to help you work well on your sites:

  • Always save a large amount of data in your dev database, if you enter millions of dummy rows, this will exaggerate performance issues while you are still in development.
  • Use performance tests, if we have a site with a large volume, we install at least a test on the page to check the time of the health check. This allows you to select remote pages.
  • Avoid really complex LINQ statements, they are usually (but not always) wrong, basically you can just achieve the goal.
  • List your set as soon as you have the correct data. This avoids accidentally complicating the request in your displayed code. (i.e. use ToList or ToArray)
  • Use EFProfiler or SQLProfiler for complex queries to verify that SQL seems reasonable.

Hope this helps, the general form is more an art than a science. Its a little sliding scale.

+3
source

Source: https://habr.com/ru/post/1394836/


All Articles