Ric*_*est 13 asp.net-mvc entity-framework entity-framework-4.1 mvc-mini-profiler
我正在尝试使用带有EFCodeFirst的mvc-mini-profiler我正在创建一个DbProfiledConnection并将其传递给构造中的DbContext,如下所示.应用程序继续按预期工作,sql未向Profiler公开.
public class WebContext : DbContext
{
static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString);
static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection);
public WebContext()
: base(_profiledConnection, true)
{
}
Run Code Online (Sandbox Code Playgroud)
我糟透了
我已修改它,以便在我的UnitOfWork中构建我的WebContext时,我传入ProfiledDbConnection
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}
Run Code Online (Sandbox Code Playgroud)
我已经检查过并且在Application_BeginRequest中设置了MiniProfier Current,当我尝试查询数据库时,它会返回ProfiledDbConnection,并在ProfiledDbProviderServices类中抛出错误.
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}
Run Code Online (Sandbox Code Playgroud)
此方法返回"提供程序未返回ProviderManifestToken字符串".错误
我怀疑这与静态字段初始化程序有关.Web应用程序上的连接永远不应该是静态的(但最多是请求特定的).
关键是:ProfiledDbConnection
实际出现了什么?如果您当前正在进行概要分析(在当前请求上),则该Get
方法ProfiledDbConnection
仅返回a ,并且针对该MiniProfiler
请求上的实例分析连接.
如果使用静态字段,则有两种情况:
MiniProfiler.Current
是null 归档时间: |
|
查看次数: |
2513 次 |
最近记录: |