Im looking for otimization.
When I call Count method in Entity Framework, does it process all the columns or only one or what?
If you also have any official site talking about this, I would appreciate.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I did some tests a while ago and found out that EF does a count on the server, it sends a query with a SELECT COUNT so it does not load all records for sure.
about the columns, if you are referring to the difference between
COUNT(*)orCOUNT(Id)orCOUNT(1)I have read somewhere a while ago that for SQL Server there is no difference, theCOUNT(*)is optimized asCOUNT(1)anyway.you could read many articles online or question here on SO… not excatly 100% what you asked but similar topics on performances of EF and ORM…
How to COUNT rows within EntityFramework without loading contents?
http://ayende.com/blog/4387/what-happens-behind-the-scenes-nhibernate-linq-to-sql-entity-framework-scenario-analysis
How to optimize Entity Framework Queries