我正在尝试将mvc-mini-profiler与EFCodeFirst一起使用,我正在创建一个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)
{
}哦,我的错。
我对它进行了修改,以便在UnitOfWork中构造WebContext时传入一个ProfiledDbConnection
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}我检查过了,在Application_BeginRequest中设置了MiniProfier Current,当我尝试查询数据库时,它会返回一个ProfiledDbConnection,在ProfiledDbProviderServices类中抛出一个错误。
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}此方法返回“提供程序未返回ProviderManifestToken字符串”。错误
发布于 2011-06-09 19:12:10
我怀疑这与静态字段初始化器有关。web应用程序上的连接永远不应该是静态的(但最多只能是特定于请求的)。
关键是:ProfiledDbConnection到底是什么样子的?仅当您当前正在分析(针对当前请求),并且针对该请求的MiniProfiler实例分析连接时,Get方法才会返回ProfiledDbConnection。
如果使用静态字段,则有两种情况:
MiniProfiler.Current为nullhttps://stackoverflow.com/questions/6291727
复制相似问题