我正在尝试在EFCodeFirst中使用mvc-mini-profiler我创建了一个DbProfiledConnection并将其传递给DbContext,如下所示。该应用程序继续按预期工作,但不会暴露给Profiler。使用mvc-mini-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)
{
}
oops my bad。
我已经修改了它,这样,当我WebContext在我的UnitOfWork构建我在ProfiledDbConnection通过
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}
我检查和MiniProfier目前已被的Application_BeginRequest设置并返回一个ProfiledDbConnection当我然后尝试查询数据库,在ProfiledDbProviderServices类中抛出错误。
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}
此方法返回“提供程序没有返回ProviderManifestToken字符串”。错误
顺便说一句,一个静态C连接是危险的 - 它应该是特定于请求的。 – 2011-06-09 11:08:46
为什么静态连接很危险?另外,如果我只在控制器的顶部启动新的上下文,而不是在每个请求中启动一个新的上下文,我是否实际上使用了静态上下文? – sirtimbly 2011-06-27 19:56:38