我有一个使用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);
}
编译错误报告以下问题:
我注意到我可以创建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/