Why is Entity Framework taking 30 seconds to load records when the generated query only takes 1/2 of a second?

前端 未结 4 1070
深忆病人
深忆病人 2020-12-08 16:34

The executeTime below is 30 seconds the first time, and 25 seconds the next time I execute the same set of code. When watching in SQL Profiler, I immediately see a login, t

4条回答
  •  囚心锁ツ
    2020-12-08 17:28

    It is because of the Include. My guess is that you are eager loading a lot of objects into the memory. It takes much time to build the c# objects that corresponds to your db entities.

    My recommendation for you is to try to lazy load only the data you need.

提交回复
热议问题