.Include() vs .Load() performance in EntityFramework

后端 未结 6 2070
抹茶落季
抹茶落季 2020-11-28 04:01

When querying a large table where you need to access the navigation properties later on in code (I explicitly don\'t want to use lazy loading) what will perform better

6条回答
  •  爱一瞬间的悲伤
    2020-11-28 04:32

    Include() will be written to SQL as JOIN: one database roundtrip.

    Each Load()-instruction is "explicitly loading" the requested entities, so one database roundtrip per call.

    Thus Include() will most probably be the more sensible choice in this case, but it depends on the database layout, how often this code is called and how long your DbContext lives. Why don't you try both ways and profile the queries and compare the timings?

    See Loading Related Entities.

提交回复
热议问题