Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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();
        }

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
357 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...