Entity Framework is Microsoft’s ORM library that enables developers to work with domain-specific objects and eliminates the dependency of SQL queries in a project's data access layer. Entity Framework can also significantly reduce the development time. Visual Studio has good support of EF Wizard and drag-and-drop tools that help generate EF objects without writing a single line of code.
Entity Framework is based on ADO.NET, which means ADO.NET is faster than Entity Framework.
Entity Framework usage considerations
- Make sure your database is indexed, as it is a major factor in Entity Framework’s query performance.
- Try to fetch only the required number of rows rather than fetching a large number of records.
- Reduce the fetch size as much as possible.
- You should use stored procedures, functions and compiled query wherever and whenever they are required.
- You need to carefully handle the tables with nested relationships or deep hierarchy as Entity Framework performs slower in such cases.
- Breaking your EDMX into a module-specific tables model can be a handy approach as well but make sure you handle it carefully as there is a limitation that the Entities from different models cannot be shared even though they refer to the same table in the database.
- Use Profilers, and run it when as a part of the unit test to know the query is getting fired as you expect it to trigger.
- Entity Framework generates a Select-Where-In-Select style query in case of join and lambda expressions that can be a concern for you as well but you can find them easily by using profilers.
- If you are updating records in look please make sure to save it only once instead of saving it multiple times.
- If you are fetching records for viewing, then only in that case, you can Disable change tracking for the entity as it is not needed.
- Avoid fetching all the fields if not required; try to use data model/entities for the same.
- Disable the Change Tracking if it is not required.