在DbContext中,您可以配置以下两个参数:
context.Configuration.ProxyCreationEnabled = true;
context.Configuration.LazyLoadingEnabled = true;
Run Code Online (Sandbox Code Playgroud)
我的理解是,要启用延迟加载,您必须能够为实体创建代理.换句话说,两个参数都需要设置为true才能启用延迟加载.
1.为什么两个参数都存在,为什么要配置这两个参数?
2.以下配置的效果如何?
// Can't create proxies but can lazy load
context.Configuration.ProxyCreationEnabled = false;
context.Configuration.LazyLoadingEnabled = true;
// Can create proxies but can't lazy load
context.Configuration.ProxyCreationEnabled = true;
context.Configuration.LazyLoadingEnabled = false;
Run Code Online (Sandbox Code Playgroud)