我正在嘗試在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