问题描述
我正在夜间构建通道上使用Entity Framework 7(现在我使用版本EntityFramework.7.0.0-beta2-11524),我正在尝试记录EF产生的查询,只是出于好奇。 / p>
我正在编写一个简单的控制台程序,我尝试使用,EF6使用,但 DbContext.Database.Log
在实体框架7上不可用。有没有办法记录或只是看看EF7生成的SQL?
对于那些使用EF7的人,上述都不适用于我。但这是我如何工作。 (来自@avi cherry的评论)
在您的 Startup.cs 中,您可以在其中配置一系列配置。它应该看起来像下面(除了你的东西)。
public void Configure(IApplicationBuilder app,ILoggerFactory loggerFactory)
{
//这是魔术线
loggerFactory.AddDebug(LogLevel.Debug); //以前的LogLevel.Verbose
//你的其他东西
}
I am using Entity Framework 7 on the nightly build channel (right now I'm using version EntityFramework.7.0.0-beta2-11524) and I'm trying to log the queries that EF generates just out of curiosity.
I'm writing a simple console program, I tried using the same logging technic that EF6 uses, but DbContext.Database.Log
is not available on Entity Framework 7. Is there a way to log or just take a peek at the SQL generated by EF7?
For those using EF7 none of the above worked for me. But this is how i got it working. (from @avi cherry's comment)
In your Startup.cs you proably have a Configure method with a bunch of configurations in it. It should look like below (in addition to your stuff).
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
//this is the magic line
loggerFactory.AddDebug(LogLevel.Debug); // formerly LogLevel.Verbose
//your other stuff
}
这篇关于如何使用Entity Framework 7记录查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!