What are the performance tips that every ADO.NET EF developer should know about?
Please put each tip per answer and explain why the tip is good (e.g. by minimizing DB roundtrips).
One of the biggest reasons not to use Entity Framework Core is that your application needs the fastest possible data access. Some applications do a lot of heavy data operations with very high-performance demands, but usually business applications don't have that high of a performance demand.
In short, Dapper.NET is slightly faster than straight ADO.NET.
Use ObjectContext#GetObjectByKey()
to retrieve entities by their key instead of using First()
(or FirstOrDefault
) operator in the LINQ query. The latter will hit the database everytime while the former will search the EF cache (ObjectStateManager
to be specific) for the entity first and won't hit the database if the entity with the specified key is found.
References
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With