Accessing SQL from Entity Framework Core Queries in ASP.NET Core












1















In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/



The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.



I am using using .net core 2.1 as well.



Is there another or similar approach available?



Thanks.










share|improve this question

























  • In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

    – Gabriel Luci
    Nov 24 '18 at 20:58











  • @GabrielLuci Yes, agreed. The reference you provided has the issue.

    – JamieMeyer
    Nov 24 '18 at 21:02













  • So did you try that one? People in the comments claim that it works with 2.1

    – Gabriel Luci
    Nov 24 '18 at 21:42











  • The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

    – JamieMeyer
    Nov 24 '18 at 21:47













  • Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

    – Gabriel Luci
    Nov 24 '18 at 22:26
















1















In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/



The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.



I am using using .net core 2.1 as well.



Is there another or similar approach available?



Thanks.










share|improve this question

























  • In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

    – Gabriel Luci
    Nov 24 '18 at 20:58











  • @GabrielLuci Yes, agreed. The reference you provided has the issue.

    – JamieMeyer
    Nov 24 '18 at 21:02













  • So did you try that one? People in the comments claim that it works with 2.1

    – Gabriel Luci
    Nov 24 '18 at 21:42











  • The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

    – JamieMeyer
    Nov 24 '18 at 21:47













  • Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

    – Gabriel Luci
    Nov 24 '18 at 22:26














1












1








1








In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/



The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.



I am using using .net core 2.1 as well.



Is there another or similar approach available?



Thanks.










share|improve this question
















In a post in the last week or so, someone made reference to a post: http://rion.io/2016/10/19/accessing-entity-framework-core-queries-behind-the-scenes-in-asp-net-core/



The blog outlined using internals of EF to show the generated SQL for a given EF query. Having a tool like this is invaluable, and will help my EF dev team to write better code. However, as it uses internal and unsupported code, it will not build using EF 2.1.4. The reference to RelationalQueryModelVisitor is now gone, and the code will not build.



I am using using .net core 2.1 as well.



Is there another or similar approach available?



Thanks.







c# entity-framework asp.net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 22:27









Gabriel Luci

11.2k11525




11.2k11525










asked Nov 24 '18 at 20:54









JamieMeyerJamieMeyer

346214




346214













  • In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

    – Gabriel Luci
    Nov 24 '18 at 20:58











  • @GabrielLuci Yes, agreed. The reference you provided has the issue.

    – JamieMeyer
    Nov 24 '18 at 21:02













  • So did you try that one? People in the comments claim that it works with 2.1

    – Gabriel Luci
    Nov 24 '18 at 21:42











  • The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

    – JamieMeyer
    Nov 24 '18 at 21:47













  • Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

    – Gabriel Luci
    Nov 24 '18 at 22:26



















  • In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

    – Gabriel Luci
    Nov 24 '18 at 20:58











  • @GabrielLuci Yes, agreed. The reference you provided has the issue.

    – JamieMeyer
    Nov 24 '18 at 21:02













  • So did you try that one? People in the comments claim that it works with 2.1

    – Gabriel Luci
    Nov 24 '18 at 21:42











  • The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

    – JamieMeyer
    Nov 24 '18 at 21:47













  • Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

    – Gabriel Luci
    Nov 24 '18 at 22:26

















In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

– Gabriel Luci
Nov 24 '18 at 20:58





In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757

– Gabriel Luci
Nov 24 '18 at 20:58













@GabrielLuci Yes, agreed. The reference you provided has the issue.

– JamieMeyer
Nov 24 '18 at 21:02







@GabrielLuci Yes, agreed. The reference you provided has the issue.

– JamieMeyer
Nov 24 '18 at 21:02















So did you try that one? People in the comments claim that it works with 2.1

– Gabriel Luci
Nov 24 '18 at 21:42





So did you try that one? People in the comments claim that it works with 2.1

– Gabriel Luci
Nov 24 '18 at 21:42













The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

– JamieMeyer
Nov 24 '18 at 21:47







The original post, as well as my previous response to you indicate this is the case. Do you have a different result?

– JamieMeyer
Nov 24 '18 at 21:47















Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

– Gabriel Luci
Nov 24 '18 at 22:26





Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post.

– Gabriel Luci
Nov 24 '18 at 22:26












2 Answers
2






active

oldest

votes


















1














Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.



Here is what I did:




  1. Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.

  2. Added Microsoft.EntityFrameworkCore version 2.1.4 from NuGet.

  3. Created an IQueryableExtensions class and pasted the code.


It compiles.



The RelationalQueryModelVisitor class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.






share|improve this answer

































    0














    Would using their logging functionality be sufficient?



    https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging



    public static readonly LoggerFactory MyLoggerFactory
    = new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    => optionsBuilder
    .UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
    .UseSqlServer(...);





    share|improve this answer























      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%2f53462278%2faccessing-sql-from-entity-framework-core-queries-in-asp-net-core%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.



      Here is what I did:




      1. Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.

      2. Added Microsoft.EntityFrameworkCore version 2.1.4 from NuGet.

      3. Created an IQueryableExtensions class and pasted the code.


      It compiles.



      The RelationalQueryModelVisitor class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.






      share|improve this answer






























        1














        Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.



        Here is what I did:




        1. Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.

        2. Added Microsoft.EntityFrameworkCore version 2.1.4 from NuGet.

        3. Created an IQueryableExtensions class and pasted the code.


        It compiles.



        The RelationalQueryModelVisitor class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.






        share|improve this answer




























          1












          1








          1







          Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.



          Here is what I did:




          1. Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.

          2. Added Microsoft.EntityFrameworkCore version 2.1.4 from NuGet.

          3. Created an IQueryableExtensions class and pasted the code.


          It compiles.



          The RelationalQueryModelVisitor class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.






          share|improve this answer















          Use the class in this link, which does work in .NET Core 2.1. Yes, I know you said you tried it, but I just tried it and it worked, so there must be something else going wrong in your project. Tell us the compiler error you are getting and we can help further.



          Here is what I did:




          1. Created a new ASP.NET Core project and made sure it's targetting .NET Core 2.1.

          2. Added Microsoft.EntityFrameworkCore version 2.1.4 from NuGet.

          3. Created an IQueryableExtensions class and pasted the code.


          It compiles.



          The RelationalQueryModelVisitor class does still exist in .NET Core 2.1. The documentation shows it is still there (notice the "Entity Framework Core 2.1" in the top left of the docs) and the current source code on GitHub still shows it there.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 1:55

























          answered Nov 25 '18 at 0:01









          Gabriel LuciGabriel Luci

          11.2k11525




          11.2k11525

























              0














              Would using their logging functionality be sufficient?



              https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging



              public static readonly LoggerFactory MyLoggerFactory
              = new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});

              protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
              => optionsBuilder
              .UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
              .UseSqlServer(...);





              share|improve this answer




























                0














                Would using their logging functionality be sufficient?



                https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging



                public static readonly LoggerFactory MyLoggerFactory
                = new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});

                protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                => optionsBuilder
                .UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
                .UseSqlServer(...);





                share|improve this answer


























                  0












                  0








                  0







                  Would using their logging functionality be sufficient?



                  https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging



                  public static readonly LoggerFactory MyLoggerFactory
                  = new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});

                  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                  => optionsBuilder
                  .UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
                  .UseSqlServer(...);





                  share|improve this answer













                  Would using their logging functionality be sufficient?



                  https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging



                  public static readonly LoggerFactory MyLoggerFactory
                  = new LoggerFactory(new {new ConsoleLoggerProvider((_, __) => true, true)});

                  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                  => optionsBuilder
                  .UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time
                  .UseSqlServer(...);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 '18 at 23:13









                  MohoMoho

                  11.1k11723




                  11.1k11723






























                      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%2f53462278%2faccessing-sql-from-entity-framework-core-queries-in-asp-net-core%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

                      Wiesbaden

                      Marschland

                      Dieringhausen