在EF永久禁用Configuration.ProxyCreationEnabled? [英] Permanently disable Configuration.ProxyCreationEnabled in EF?
问题描述
而不必做对每个查询以下的,有没有只是设置了全球价值的方式?有模型视图中的惰性加载设置,但似乎没有成为该ProxyCreation的设置。
Instead of having to do the following on every query, is there a way to just set that value globally? There is a lazyloading setting in the model view, but there does not seem to be a setting for the ProxyCreation.
using (var context = new LabEntities())
{
**context.Configuration.ProxyCreationEnabled = false;**
var Query = from s in context.EAssets
.Include("Server").Include("Type").Include("Type.Definition")
where (s.Type.Definition.b_IsScannable == true) &&
(s.Server.s_Domain == Environment.UserDomainName || s.Server.s_Domain == null)
select s;
var Entities = Query.ToList();
}
我不完全理解此选项的好处,但我知道,在Visual Studio中的标签我的胡言乱语串行后缀的所有对象,并使用调试器不合理使。
I don’t fully understand the benefits of this option, but i know that in visual studio is tags all my objects with gibberish serial suffixes and makes using the debugger unreasonable.
推荐答案
您可以在构造函数中禁用它,所以它被停用,任何时候你创建一个新的上下文:
You can disable it in the constructor, so that it gets disabled anytime you create a new context:
public class LabEntities : DbContext
{
public LabEntities()
{
Configuration.ProxyCreationEnabled = false;
}
}
这篇关于在EF永久禁用Configuration.ProxyCreationEnabled?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!