Mini Profiler 从 1.7 升级到 1.9 破坏了现有代码
我有一个使用 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的建议,我成功地构建了代码。我现在得到以下运行时异常:
在“MvcMiniProfiler.Data.ProfiledDbConnection”类型的存储提供程序实例上调用“get_ProviderFactory”方法后,返回 null。商店提供商可能无法正常运行。
通过检查 ILSpy 中的 ProfiledDbConnection,我注意到它不再覆盖 DbProviderFactory。这似乎是错误的原因,因为基本实现返回 null。有人能够解决这个问题吗?
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' does not contain a definition for 'Get'.
- The name 'ObjectContextUtils' does not exist in the current context.
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.
Regarding ObjectContextUtils, I have no clue of what I am supposed to use.
How can I fix these issues?
Update:
By following @monkeychatter's recommendations, I managed to build the code. I now get the following runtime exception:
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚经历了同样的事情,不幸的是大多数/所有文档都显示了“旧”方式。此功能的大部分已移至 ProfiledDbConnection 类本身。要在 ProfiledDbConnection 上获取 ObjectContext 扩展,您还需要引用 nuget 包“MiniProfiler.EF”中的程序集。以下是获得 1.9 中等效代码的编辑。
更新:
根据您更新的问题,我将替换之前解决方案中的行,如下所示。这包括修复 ProviderFactory 问题的覆盖:
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.
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: