I am working with Entity Framework 4.1 and C#.
Which one is the most suitable for best performance?
If so - why? (any links for additional readings) ?
bool isBoarding = invoice.Allocations.Where(a => a.Service.Key == "boarding").Count() > 0;
OR
bool isBoarding = invoice.Allocations.Any(a => a.Service.Key == "boarding");
The conclusions are obvious: in almost every test conducted by Chad, Entity Framework Core 3 is faster than Entity Framework 6 – exactly 2.25 to 4.15 times faster! So if performance is important to your application and it operates on large amounts of data, EF Core should be a natural choice. Is it faster than Dapper?
You can improve the overall performance of queries in the Entity Framework by using the following strategies. Generating views based on an entity model is a significant cost the first time that an application executes a query.
In order to better understand the performance of queries in the Entity Framework, it is helpful to understand the operations that occur when a query executes against a conceptual model and returns data as objects. The following table describes this series of operations. Once in each application domain.
var count = entities.Post.Where (p => p.SiteID == 1 && p.CreatedDate != null).Query ().Count (); Sometimes it is useful to know how many entities are related to another entity in the database without actually incurring the cost of loading all those entities. The Query method with the LINQ Count method can be used to do this. For example:
Count I believe will cause all records to be iterated over, whereas Any will stop at the first it finds.
EDIT: Just found an excellent post about count vs any take a look here
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