Get added entities in the query (next)

I want to complete my yesterday post.


If you just want to get the entities Count, it is useless to load all the entities in memory.


So in this case, it’s better to do something like this:


context.MyEntitySet.Count() + context.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(e => e.Entity).OfType<MyEntityType>().Count() – context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted).Select(e => e.Entity).OfType<MyEntityType>().Count()

This entry was posted in 7671, 7674. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>