ASP.NET MVC3 어플리케이션으로 데이터베이스 프로파일 링을 설정하려고합니다. 나는 이것에 대해 찾을 수있는 모든 블로그를 따랐다 그 결과는 다음과 같습니다코드를 처음 사용할 때 MvcMiniProfiler가 데이터베이스 프로파일 링을 표시하지 않습니다.
<system.data>
<DbProviderFactories>
<remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" />
<add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider" description="MvcMiniProfiler.Data.ProfiledDbProvider" type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler, Version=1.6.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>
</system.data>
의 Global.asax에서 :
protected void Application_Start()
{
Bootstrapper.Run();
MiniProfiler.Settings.SqlFormatter = new SqlServerFormatter();
var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["TemplateDB"].ConnectionString);
var profiled = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(factory);
Database.DefaultConnectionFactory = profiled;
}
protected void Application_BeginRequest()
{
if (Request.IsLocal) { MiniProfiler.Start(); }
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
컨트롤러에서 :
public ActionResult About()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("call database"))
{
ProjectResult result = projectService.Create("slug");
return View();
}
}
의 Web.config에서
저장소 패턴을 사용 중이고 내 EF 코드가 MVC 응용 프로그램에서 참조하는 다른 프로젝트에 처음으로 있습니다. .
내 데이터베이스 클래스는 다음과 같습니다
public class DatabaseFactory : Disposable, IDatabaseFactory
{
private readonly string connectionString;
private Database database;
public DatabaseFactory(string connectionString)
{
Check.Argument.IsNotNullOrEmpty(connectionString, "connectionString");
this.connectionString = connectionString;
}
public Database Get()
{
return database ?? (database = new Database(connectionString));
}
protected override void DisposeCore()
{
if (database != null)
database.Dispose();
}
}
이 내 응용 프로그램을 실행할 때 프로파일이 전혀 데이터베이스 프로파일이 표시되지 않습니다, 단지 일반 실행 : 같은
public class Database : DbContext
{
public Database(string connection) : base(connection)
{
}
public DbSet<Project> Projects { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Project>().Property(p => p.Slug).IsUnicode().IsRequired().IsVariableLength().HasMaxLength(64);
}
public virtual void Commit()
{
base.SaveChanges();
}
}
내 데이터베이스 공장이 보인다 컨트롤러/뷰의 시간.
도움을 주시면 감사하겠습니다.
감사
동일한 문제가 발생했습니다. [링크] http://stackoverflow.com/questions/6889929/mvc-mini-profiler-v1-7-on-ef-4-1-code-first-project-doesnt-profile-sql [/ link] 1.7 버전은 @counsellorben이 준 응답에 따라 일을 설정합니다. 그리고 토마스처럼 여전히 SQL 프로파일 링을 사용할 수 없습니다. –