在 EF 中永久禁用 Configuration.ProxyCreationEnabled? [英] Permanently disable Configuration.ProxyCreationEnabled in EF?

查看:42
本文介绍了在 EF 中永久禁用 Configuration.ProxyCreationEnabled?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不必对每个查询都执行以下操作,有没有办法全局设置该值?模型视图中有一个lazyloading设置,但是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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆