LazyLoadingEnabled setting doesn't seem to work in EF 5

后端 未结 3 598
栀梦
栀梦 2021-01-18 23:49

I\'m using EF Model first with POCO entities and with custom DbContexts. My problem is that setting LazyLoadingEnabled=false does not affect anything, navigatio

3条回答
  •  遇见更好的自我
    2021-01-19 00:51

    "EF still loads the Programs and OwnerProgram properties of the Program class"

    This is the correct behavior, but instead of loading the navigation properties lazily, it loads them eagerly.

    This means that the database queries required to retrieve the navigation property values are executed immediately when the Program entity is retrieved and the navigation properties are populated.

    When LazyLoadingEnabled is set to true these queries aren't triggered until you attempt to access the navigation properties. This also applies to when you're hovering your mouse over navigation properties and the debugger is attached, which may lead you to think that the entities aren't being lazily loaded when in fact they are - the debugger is accessing the navigation property, so Entity Framework loads it.

    You can run a SQL profiler such as this one to see exactly when queries are being triggered as you debug your code.

提交回复
热议问题