Using Mini-Profilier with EF 4.3 & MVC 4 without creating the database

后端 未结 4 2074
不知归路
不知归路 2020-12-29 04:46

I have an issue where we are using EF 4.3 Code First against an existing database. I want to use the Mini-Profiler with EF and call

MvcMiniProfiler.MiniPro         


        
4条回答
  •  臣服心动
    2020-12-29 05:15

    I started a new MVC 4 project and installed/updated the following NuGet packages:

    • EntityFramework
    • MiniProfiler
    • MiniProfiler.EF

    I turned off the database initialization strategy in Code First inside of my database context.

    public class EmployeeContext : DbContext
    {
        static EmployeeContext()
        {
            Database.SetInitializer( null ); // must be turned off before mini profiler runs
        }
    
        public IDbSet Employees { get; set; } 
    }
    

    The mini profiler is working properly. I created the one table database by hand.

    Turning off the database initializer in the static constructor is important. If you do it elsewhere then it's possible that the mini profiler code runs before your code and hence the queries to the __MigrationHistory table that shouldn't be occurring at all.

提交回复
热议问题