我在我的项目中集成了 Entity Framework 和 CodeFirstStoredProc 库。我想记录两个库执行的查询。以前我使用 EF 提供的 Database.Log delegate,但由于我也想记录来自其他库的查询,因此我决定集成 Miniprofiler。
我使用下面的代码来获取变量中的查询日志result:
MiniProfilerEF6.Initialize();
MiniProfiler.StartNew("Test");
using (MiniProfiler.Current.Step("Level 1"))
{
DbConnection spConnection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
ProfiledDbConnection profileSpConnection = new ProfiledDbConnection(spConnection, MiniProfiler.Current);
using (EfDataContext db = new EfDataContext(profileSpConnection))
{
List<Domain.PersonEntity> data = db.Persons.ToList();
}
using (StoredProcedureContext db = new StoredProcedureContext(profileSpConnection))
{
List<GetPersonResult> data = db.GetPerson.CallStoredProc(new Domain.GetPersonParameter { IsActive = true }).ToList<GetPersonResult>();
}
string result = MiniProfiler.Current.RenderPlainText();
}
MiniProfiler.Current.Stop();
Run Code Online (Sandbox Code Playgroud)
我期望输出查询包含所有详细信息,但不幸的是我得到以下结果:
Manprit-PC at 11/15/2018 2:24:27 PM
Test = ms
> Level 1 = …Run Code Online (Sandbox Code Playgroud)