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.

8
  • In that article, one of the comments points to this: gist.github.com/nour-s/3bbf9b2588faa6b849393639a8b39757 Commented Nov 24, 2018 at 20:58
  • @GabrielLuci Yes, agreed. The reference you provided has the issue. Commented Nov 24, 2018 at 21:02
  • So did you try that one? People in the comments claim that it works with 2.1 Commented Nov 24, 2018 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? Commented Nov 24, 2018 at 21:47
  • Maybe you misunderstand me. The link I gave has different code than the article you mention in your original post. Commented Nov 24, 2018 at 22:26

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Would using their logging functionality be sufficient?

https://learn.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(...);

Comments

0

It's in the Microsoft.EntityFrameworkCore.Relational nuget package.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.