如何一起使用 Universal Membership Provider、EF 和 MiniProfiler?

发布于 2025-01-02 09:15:06 字数 230 浏览 0 评论 0原文

如果我使用通用成员资格提供程序和单独的数据库、实体框架并为 EF 4.2 启用 Mini Profiler。当我第一次在主视图中检查用户凭据时,出现错误 {“数据库中已有一个名为“应用程序”的对象。”}

如果我转向删除 MiniProfilerEF.Initialize(); 然后我就不再收到错误。

有什么想法吗?

我可以停止分析默认连接吗?

If I use the Universal Membership Provider and a seperate database, Entity Framework and enable Mini Profiler for EF 4.2. I get error {"There is already an object named 'Applications' in the database."} when I first hit a line checking user credentials in my home view.

If I turn remove MiniProfilerEF.Initialize(); then I stop getting the error.

Any ideas?

Can I stop profiling the defaultconnection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2025-01-09 09:15:06

一段时间以来,我一直在为这个问题而苦恼。今天又进行了一些挖掘,并能够使其正常工作。这就是我所做的。在 MiniProfiler.cs 中,我定义了两个方法,如下所示:

public static DbConnection GetConnection()
{
    var connectionString = ConfigurationManager.ConnectionStrings["MyModelConnectionString"].ConnectionString;
    var entityConnStr = new EntityConnectionStringBuilder(connectionString);
    var realConnection = new SqlConnection(entityConnStr.ProviderConnectionString);
    return realConnection;            
}

public static IMyModelsInterface GetProfiledContext()
{           
     var connection = new MvcMiniProfiler.Data.EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
     var context = connection.CreateObjectContext<MyModel>();
     return context; 
}

注意: 这两个方法可能不应该在 MinProfilerPackage 中定义,但这是我第一次让它工作。

然后调用 GetProfiledContext() 并在需要分析查询时使用返回的上下文。我使用 Ninject 将此配置文件上下文注入到我的控制器工厂中。我的调用看起来像这样:

public NinjectControllerFactory()
{
    ninjectKernel = new StandardKernel();
    AddBindings();
}
private void AddBindings()
{
    var context = MiniProfilerPackage.GetProfiledContext();
    IUnitOfWork uow = new UnitOfWork(context);
    ninjectKernel.Bind<IRepository>().To<GenericRepository>().WithConstructorArgument("paramUnitOfWork", uow);  

     // ... rest of the method
 }

NinjectControllerFactory 是我的控制器工厂,在 Application_Start 中设置。

 protected void Application_Start()
 {
     // Add in DI for controller and repo associations
     ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

     // ... rest of the method
  }

I have been banging my head against this issue for awhile now. Did some more digging today and was able to get it working. Here is what I did. In MiniProfiler.cs I defined two methods as follows:

public static DbConnection GetConnection()
{
    var connectionString = ConfigurationManager.ConnectionStrings["MyModelConnectionString"].ConnectionString;
    var entityConnStr = new EntityConnectionStringBuilder(connectionString);
    var realConnection = new SqlConnection(entityConnStr.ProviderConnectionString);
    return realConnection;            
}

public static IMyModelsInterface GetProfiledContext()
{           
     var connection = new MvcMiniProfiler.Data.EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
     var context = connection.CreateObjectContext<MyModel>();
     return context; 
}

NOTE: These two methods probably shouldn't be defined in MinProfilerPackage, but this was my first past/hack to get it working.

Then call GetProfiledContext() and use the context returned whenever you want the queries profiled. I injected this profile context into my controller factory using Ninject. My call looks something like this:

public NinjectControllerFactory()
{
    ninjectKernel = new StandardKernel();
    AddBindings();
}
private void AddBindings()
{
    var context = MiniProfilerPackage.GetProfiledContext();
    IUnitOfWork uow = new UnitOfWork(context);
    ninjectKernel.Bind<IRepository>().To<GenericRepository>().WithConstructorArgument("paramUnitOfWork", uow);  

     // ... rest of the method
 }

NinjectControllerFactory is my controller factory that gets set in Application_Start.

 protected void Application_Start()
 {
     // Add in DI for controller and repo associations
     ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

     // ... rest of the method
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文