hello,
assume code as below:
public class Blog
{
public int ID{get;set;}
public virtual ICollection<Post>Posts {get;set;}
}
then I want to get the quantity of posts of a blog:
int c = blog.Posts.Count;
//or
int c = blog.Posts.Count();
I find that the generated SQL shows that EF will get all posts of a blog, than calculate the Count() in memory.
if I want to let SQL caculate Count, I must write :
context.Posts.Count(p => p.Bolg == someblog)
What is right way? I like the simple code of blog.Posts.Count, but it seems with bad performance.
Thank you!
View Complete Post