Home

Entity Framework Core, manual DbContext instantiation and SQL logging

When a connection is selected in a dropdown, LinqPad shows SQL that was generated by a provider in SQL tab (through internal interception mechanism). But, if DbContext is instantiated in code, is there is a way to configure LinqPad or adjust code to be able to view SQL queries generated by EF in the same manner?

I have only found a way through custom LoggerFactory and ILogger implementation with Util.SqlOutputWriter.WriteLine call and passing this factory instance to UseLoggerFactory(Logger.MyLoggerFactory) method call in DbContext.OnConfiguring method. But this SQL output has a different format and this is not a very convenient approach, because every time I need to view SQL for my code with manual DbContext instantiation I should add this bulky Logger configuration.

Comments

Sign In or Register to comment.