EF Core enable Lazy Loading conditionally

前端 未结 1 885
Happy的楠姐
Happy的楠姐 2021-01-18 22:00

I am looking for a possible way to enable Lazy Loading in my DbContext but not all the time, only in specific instances when I need it. Because of issues like t

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 22:21

    You can use ChangeTracker.LazyLoadingEnabled property:

    Gets or sets a value indicating whether navigation properties for tracked entities will be loaded on first access.

    The default value is true.

    e.g.

    context.ChangeTracker.LazyLoadingEnabled = false;
    var query = context.Set<…>()...;
    

    0 讨论(0)
提交回复
热议问题