efcore 2.2 turn off proxy creation for a specific query when Using LazyLoadedProxies

c# ef-core-2.2 entity-framework entity-framework-core

Question

I have an application where in most places I want to be able to use the LazyLoadedProxies so am calling UseLazyLoadingProxies in OnConfiguring.

There are specific queries that I don't want proxies as I am going to serialize the object and others where it may be passed to another part of the application and I don't want any N+1 errors so want to ensure that I am not getting a Proxy.

How can you disable Proxies for a specific query.

1
0
1/20/2019 2:56:09 PM

Popular Answer

I don't want any N+1 errors so want to ensure that I am not getting a Proxy.

No! you cannot disable proxy creation in EF Core query. But for JSON serialization you can turn it off as follows:

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddMvc()
        .AddJsonOptions(
            options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
        );

    ...
}
1
1/20/2019 4:16:16 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow