asp.net - Mini Profiler从1.7升级到1.9会破坏现有代码

标签 asp.net entity-framework mvc-mini-profiler

我有一个使用mvc-mini-profiler的asp.net项目。我使用的是NuGet软件包的1.7版,我注意到有一个更新的软件包,其版本为1.9。我更新了程序包,现在我的代码不再编译。无法编译的代码是:

public static T GetProfiledContext<T>() where T : System.Data.Objects.ObjectContext
{
    var conn = GetStoreConnection<T>();
    if (_enableProfiling)
    {
        conn = ProfiledDbConnection.Get(conn);
    }
    return ObjectContextUtils.CreateObjectContext<T>(conn);
}

编译错误报告以下问题:
  • 'MvcMiniProfiler.Data.ProfiledDbConnection'不包含'Get'的定义。
  • 在当前上下文中不存在名称“ObjectContextUtils”。

  • 我注意到我可以创建ProfiledDbConnection的实例,并将其传递给连接和IDbProfiler类型的对象,但是我不确定应该如何获取该对象。

    关于ObjectContextUtils,我不知道应该使用什么。

    我该如何解决这些问题?

    更新:

    通过遵循@monkeychatter的建议,我设法构建了代码。我现在得到以下运行时异常:

    A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'MvcMiniProfiler.Data.ProfiledDbConnection'. The store provider might not be functioning correctly.



    通过检查ILSpy中的ProfiledDbConnection,我注意到它不再覆盖DbProviderFactory。这似乎是导致错误的原因,因为基本实现返回null。有人能够解决此问题吗?

    最佳答案

    我只是经历了同样的事情,不幸的是,大多数/所有文档都显示了“旧的”方式。此功能的大部分已移至ProfiledDbConnection类本身。为了在ProfiledDbConnection上获得ObjectContext扩展,您还需要引用nuget包MiniProfiler.EF中的程序集。以下是获得1.9中等效代码的编辑。

    //reference extension from MvcMiniProfiler.Data
    using MvcMiniProfiler.Data;
    
    var conn = GetStoreConnection<T>();   
    if (_enableProfiling)   
    {   
        //conn = ProfiledDbConnection.Get(conn);   
        conn = new ProfiledDbConnection(conn, MiniProfiler.Current);
    }   
    //return ObjectContextUtils.CreateObjectContext<T>(conn);
    return conn.CreateObjectContext<T>();
    

    更新:
    根据您更新的问题,我将在下面的先前解决方案中替换该行。这包括解决ProviderFactory问题的替代:
        //conn = new ProfiledDbConnection(conn, MiniProfiler.Current);
        conn = new EFProfiledDbConnection(conn, MiniProfiler.Current);
    

    关于asp.net - Mini Profiler从1.7升级到1.9会破坏现有代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7257271/

    相关文章:

    javascript - Microsoft JScript 运行时错误 : Unable to get value of the property 'innerHTML' : object is null or undefined

    c# - 如何确定 Expression<Func<T, object>> 是否对 EntityFramework .Include 有效

    c# - 同时使用 Entity Framework 和 SqlConnection?

    ajax - MiniProfiler 使用 Ajax.BeginForm 抛出意外 token

    mvc-mini-profiler - 带有 Entity Framework : How to Get Connection 的 MVC 迷你分析器

    c# - 与字符串比较,对 List<string> 进行排序

    c# - CS1009 : Unrecognized escape sequence

    asp.net-mvc - ASP.NET MVC MiniProfiler 和 EntityFramework 6 初始化

    asp.net - 如何永远不显示黄色错误页面?

    c# - 带有 Oracle 的 Entity Framework ,NUMBER(10) 个错误