LazyLoading is not working
Posted: Tue 06 Oct 2015 14:33
I have a problem with the lazy loading functionality of EF6. I want tu use it (loading by "Include()") but it just doesn´t work.
Everything i tryed had absolutely no effect and i cant figure out why.
I have tryed following approaches:
changing the edmx xml:
setting the lazyloadingenabled attribute:
setting the attribute right before using the context:
i even added set the SerializerSetting for web api:
Nothing helps, the navigation properties of my entities are still created. During debugging i can navigate deeper and deeper and my application crashes during serialization to json.
The only possible way is to delete the navigation properties in my edmx model (database first) but thats not a solution because of course i want to use my entites without manually combining them.
Any solution?
I´m using .net 4.6, Ef6, the newest dotconnect and database first. (i'm creating a dll with the context in one project and use it in my web application)
Everything i tryed had absolutely no effect and i cant figure out why.
I have tryed following approaches:
changing the edmx xml:
Code: Select all
<EntityContainer Name="MyEntitiesContext" annotation:LazyLoadingEnabled="false">
Code: Select all
public MyEntitiesContext() : base("name=MyEntitiesContext", "MyEntitiesContext")
{
this.ContextOptions.LazyLoadingEnabled = false;
OnContextCreated();
}
Code: Select all
context.Configuration.ProxyCreationEnabled = false;
context.Configuration.LazyLoadingEnabled = false;
Code: Select all
public static void Register(HttpConfiguration config){
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
The only possible way is to delete the navigation properties in my edmx model (database first) but thats not a solution because of course i want to use my entites without manually combining them.
Any solution?

I´m using .net 4.6, Ef6, the newest dotconnect and database first. (i'm creating a dll with the context in one project and use it in my web application)