从现有的code 1.7〜1.9断裂迷你探查升级 [英] Mini profiler upgrade from 1.7 to 1.9 breaks existing code

查看:152
本文介绍了从现有的code 1.7〜1.9断裂迷你探查升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MVC-迷你探查一个asp.net项目。我使用的NuGet包的1.7版,我注意到,有一个更新程序包,其版本为1.9。我更新包,现在我的code不再编译。在code失败编译如下:

I have a asp.net project that uses mvc-mini-profiler. I was using version 1.7 of the NuGet package and I noticed that there is an updated package whose version is 1.9. I updated the package and now my code no longer compiles. The code that fails to compile is:

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);
}

编译错误报告的以下问题:

The compilation errors report the following issues:


  • 'MvcMiniProfiler.Data.ProfiledDbConnection不包含获​​取的定义。

  • 名称'ObjectContextUtils'不在当前上下文中存在。

我注意到,我可以创造ProfiledDbConnection的实例,并通过它连接和类型IDbProfiler的对象,但我不知道我应该如何获取该对象。

I noticed that I can create an instance of ProfiledDbConnection and pass it the connection and an object of type IDbProfiler, but I am not sure how I should obtain that object.

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

Regarding ObjectContextUtils, I have no clue of what I am supposed to use.

我该如何解决这些问题?

How can I fix these issues?

更新:

通过以下@ monkeychatter的建议,我设法建立code。我现在得到以下运行时异常:

By following @monkeychatter's recommendations, I managed to build the code. I now get the following runtime exception:

一个空被调用类型'MvcMiniProfiler.Data.ProfiledDbConnection的存储提供实例的get_ProviderFactory方法后返回。存储提供可能无法正常工作。

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。有没有人能解决这个问题?

By inspecting ProfiledDbConnection in ILSpy, I noticed that it no longer overrides the DbProviderFactory. That seems to be the cause of the error, since the base implementation returns null. Has anybody been able to work around this issue?

推荐答案

我只是通过相同的,不幸的是大多数去/所有文档显示旧的方式。大多数这种功能已被移动到ProfiledDbConnection类本身。要获得ProfiledDbConnection ObjectContext中扩展您还需要从包的NuGet MiniProfiler.EF 引用的组件。下面是编辑,以获得相当于code 1.9。

I just went through the same and unfortunately most/all documentation shows the 'old' way. The majority of this functionality has been moved to the ProfiledDbConnection class itself. To get the ObjectContext extension on ProfiledDbConnection you also need to reference an assembly from the nuget package 'MiniProfiler.EF'. Below are the edits to get the equivalent code in 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>();

更新:
每更新的问题,我将取代下面我previous解决就行了。这包括一个覆盖修复了ProviderFactory问题:

Update: Per your updated question I would replace the line in my previous solution as below. This includes an override to fix up the ProviderFactory issue:

    //conn = new ProfiledDbConnection(conn, MiniProfiler.Current);
    conn = new EFProfiledDbConnection(conn, MiniProfiler.Current);

这篇关于从现有的code 1.7〜1.9断裂迷你探查升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆