Entity Framework - Performance in count

后端 未结 5 755
清歌不尽
清歌不尽 2021-01-11 10:49

I\'ve a little question about performance with Entity Framework.

Something like

using (MyContext context = new MyContext())
{
    Document DocObject         


        
5条回答
  •  被撕碎了的回忆
    2021-01-11 11:26

    Yes, ToList() will evaluate the results (retrieving the objects from database), if you do not use ToList(), the objects aren´t retrieved from the database.

    Linq-To-Entities uses LazyLoading per default.

    It works something like this; When you query your underlying DB connection using Linq-To-Entities you will get a proxy object back on which you can perform a number of operations (count being one). This means that you do not get all the data from the DB at once but rather the objects are retrieved from the DB at the time of evaluation. One way of evaluating the object is by using ToList().

    Maybe you should read this.

提交回复
热议问题