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












0















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.










share|improve this question

























  • Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

    – Gert Arnold
    Jan 19 at 16:12











  • @TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

    – runxc1 Bret Ferrier
    Jan 20 at 14:59











  • @runxc1BretFerrier Sorry! I have misunderstood your question.

    – TanvirArjel
    Jan 20 at 16:18
















0















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.










share|improve this question

























  • Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

    – Gert Arnold
    Jan 19 at 16:12











  • @TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

    – runxc1 Bret Ferrier
    Jan 20 at 14:59











  • @runxc1BretFerrier Sorry! I have misunderstood your question.

    – TanvirArjel
    Jan 20 at 16:18














0












0








0








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.










share|improve this 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.







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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 14:56







runxc1 Bret Ferrier

















asked Jan 18 at 21:51









runxc1 Bret Ferrierrunxc1 Bret Ferrier

4,664125491




4,664125491













  • Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

    – Gert Arnold
    Jan 19 at 16:12











  • @TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

    – runxc1 Bret Ferrier
    Jan 20 at 14:59











  • @runxc1BretFerrier Sorry! I have misunderstood your question.

    – TanvirArjel
    Jan 20 at 16:18



















  • Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

    – Gert Arnold
    Jan 19 at 16:12











  • @TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

    – runxc1 Bret Ferrier
    Jan 20 at 14:59











  • @runxc1BretFerrier Sorry! I have misunderstood your question.

    – TanvirArjel
    Jan 20 at 16:18

















Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

– Gert Arnold
Jan 19 at 16:12





Note that even without lazy loading you won't necessarily escape reference loops if the model has bidirectional relationships.

– Gert Arnold
Jan 19 at 16:12













@TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

– runxc1 Bret Ferrier
Jan 20 at 14:59





@TanvirArjel I just rolled back your edit to the name of the question as you completely changed the meaning of the question. LazyLoading and Proxies are two separate things. You can have LazyLoading without Proxies.

– runxc1 Bret Ferrier
Jan 20 at 14:59













@runxc1BretFerrier Sorry! I have misunderstood your question.

– TanvirArjel
Jan 20 at 16:18





@runxc1BretFerrier Sorry! I have misunderstood your question.

– TanvirArjel
Jan 20 at 16:18












1 Answer
1






active

oldest

votes


















0















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

...
}





share|improve this answer


























  • Yes I tried that and it had no affect. I still received a Proxy class.

    – runxc1 Bret Ferrier
    Jan 20 at 15:00











  • @runxc1BretFerrier I have updated my answer! Please check it.

    – TanvirArjel
    Jan 20 at 16:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54261894%2fefcore-2-2-turn-off-proxy-creation-for-a-specific-query-when-using-lazyloadedpro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















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

...
}





share|improve this answer


























  • Yes I tried that and it had no affect. I still received a Proxy class.

    – runxc1 Bret Ferrier
    Jan 20 at 15:00











  • @runxc1BretFerrier I have updated my answer! Please check it.

    – TanvirArjel
    Jan 20 at 16:16
















0















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

...
}





share|improve this answer


























  • Yes I tried that and it had no affect. I still received a Proxy class.

    – runxc1 Bret Ferrier
    Jan 20 at 15:00











  • @runxc1BretFerrier I have updated my answer! Please check it.

    – TanvirArjel
    Jan 20 at 16:16














0












0








0








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

...
}





share|improve this 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
);

...
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 20 at 16:16

























answered Jan 19 at 3:55









TanvirArjelTanvirArjel

5,72321741




5,72321741













  • Yes I tried that and it had no affect. I still received a Proxy class.

    – runxc1 Bret Ferrier
    Jan 20 at 15:00











  • @runxc1BretFerrier I have updated my answer! Please check it.

    – TanvirArjel
    Jan 20 at 16:16



















  • Yes I tried that and it had no affect. I still received a Proxy class.

    – runxc1 Bret Ferrier
    Jan 20 at 15:00











  • @runxc1BretFerrier I have updated my answer! Please check it.

    – TanvirArjel
    Jan 20 at 16:16

















Yes I tried that and it had no affect. I still received a Proxy class.

– runxc1 Bret Ferrier
Jan 20 at 15:00





Yes I tried that and it had no affect. I still received a Proxy class.

– runxc1 Bret Ferrier
Jan 20 at 15:00













@runxc1BretFerrier I have updated my answer! Please check it.

– TanvirArjel
Jan 20 at 16:16





@runxc1BretFerrier I have updated my answer! Please check it.

– TanvirArjel
Jan 20 at 16:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54261894%2fefcore-2-2-turn-off-proxy-creation-for-a-specific-query-when-using-lazyloadedpro%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage