When I call the Count method in the Entity Framework, does it process all columns or only one or what?

Im looking for an optimization.

When I call the Count method in the Entity Framework, does it process all columns or only one or what?

If you also have an official website talking about this, I would appreciate it.

Thanks.

+6
source share
1 answer

A few years ago I did some tests and found out that EF does the counting on the server, it sends a request using SELECT COUNT, so it does not load all the records exactly.

about columns, if you mean the difference between COUNT(*) or COUNT(Id) or COUNT(1) , which I read somewhere a while ago, that there is no difference for SQL Server, COUNT(*) optimized as COUNT(1) in any case.

you could read a lot of articles on the Internet or a question here on SO ... not 100% thrilled by what you asked, but similar topics on EF and ORM ...

How to specify strings inside EntityFramework without loading content?

http://ayende.com/blog/4387/what-happens-behind-the-scenes-nhibernate-linq-to-sql-entity-framework-scenario-analysis

How to optimize Entity platform queries

+7
source

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


All Articles