jwr*_*ail 10 c# configuration proxy entity entity-framework
而不是必须在每个查询上执行以下操作,有没有办法在全局设置该值?模型视图中有一个延迟加载设置,但似乎没有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();
}
Run Code Online (Sandbox Code Playgroud)
我不完全理解此选项的好处,但我知道,在Visual Studio中的标签我毫无意义的串行后缀的所有对象,并使用调试器的不合理使.
Mar*_*eta 22
您可以在构造函数中禁用它,以便在您创建新上下文时随时禁用它:
public class LabEntities : DbContext
{
public LabEntities()
{
Configuration.ProxyCreationEnabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 17
如果您使用的是模型优先方法,意味着您有.edmx文件,则永久禁用此选项的方法是修改.Context.tt文件.此文件是构建过程用于生成DbContext派生类的代码生成模板.
打开此文件并找到构造函数:
public <#=Code.Escape(container)#>()
: base("name=<#=container.Name#>")
{
<#
WriteLazyLoadingEnabled(container);
#>
//add the following line of code
this.Configuration.ProxyCreationEnabled = false;
}
Run Code Online (Sandbox Code Playgroud)
然后添加代码行将此属性设置为false.重建项目并验证生成的上下文是否包含该行.
| 归档时间: |
|
| 查看次数: |
20665 次 |
| 最近记录: |