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