MVC-迷你探查显示错误重复查询 [英] MVC-Mini-Profiler falsely showing duplicate queries
问题描述
我一直在玩弄MVC-迷你探查,发现它非常有用。然而,在我追踪的所有网页上,我得到重复的查询报告,像下面这样。
不过,我已经跟踪SQL Server Profiler中的查询,并没有怀疑这只是击中DB一次。
我在这里缺少一个概念或有我设置了错误的方式?我已搜查高和低的人类似问题,没有运气,所以我怀疑有一个bug。
的http://本地主机:27941 /俱乐部
T + 175.2毫秒
读者
13.6毫秒
utePageHierarchy执行System.Collections.Generic.IEnumerable< T> .GetEnumerator GetResults执行ExecuteStoreCommands
选择
[Extent1]。[TeamId] AS [TeamId]
[Extent1]。[标题] AS [标题]
[Extent1]。[TitleShort] AS [TitleShort]
[Extent1]。[LogoImageId] AS [LogoImageId]
[Extent1]。[弹头] AS [弹头]
(选择
COUNT(1)AS〔A1〕
FROM [DBO]。[运动员] AS [Extent2]
WHERE [Extent1]。[TeamId] = [Extent2]。[TeamId])AS【C1】
FROM [DBO]。[队伍] AS [Extent1]
WHERE 352 = [Extent1]。[CountryId]HTTP://本地主机:27941 /俱乐部
T + 175.4毫秒
DUPLICATE阅读器
13.4毫秒
utePageHierarchy执行System.Collections.Generic.IEnumerable< T> .GetEnumerator GetResults执行ExecuteStoreCommands
选择
[Extent1]。[TeamId] AS [TeamId]
[Extent1]。[标题] AS [标题]
[Extent1]。[TitleShort] AS [TitleShort]
[Extent1]。[LogoImageId] AS [LogoImageId]
[Extent1]。[弹头] AS [弹头]
(选择
COUNT(1)AS〔A1〕
FROM [DBO]。[运动员] AS [Extent2]
WHERE [Extent1]。[TeamId] = [Extent2]。[TeamId])AS【C1】
FROM [DBO]。[队伍] AS [Extent1]
WHERE 352 = [Extent1]。[CountryId
我用EF4,并已实施的背景是这样的:
公共类BaseController:控制器
{
公共ResultsDBEntities _db; 公共BaseController()
{
VAR rootconn = ProfiledDbConnection.Get(GetStoreConnection(ConfigurationManager.ConnectionStrings[\"ResultsDBEntities\"].ConnectionString));
VAR康涅狄格州= ProfiledDbConnection.Get(rootconn);
_db = ObjectContextUtils.CreateObjectContext< ResultsDBEntities>(康涅狄格州);
} 公共静态的DbConnection GetStoreConnection< T>()其中T:System.Data.Objects.ObjectContext
{
返回GetStoreConnection(NAME =+ typeof运算(T).Name点);
} 公共静态的DbConnection GetStoreConnection(字符串entityConnectionString)
{
的DbConnection storeConnection; //让实体框架做繁重创建连接。
使用(VAR连接=新的EntityConnection(entityConnectionString))
{
//窃取EF创建的连接。
storeConnection = connection.StoreConnection; //使EF忘记,我们偷了连接(破解!)
connection.GetType()。getfield命令(_ storeConnection
BindingFlags.NonPublic可| BindingFlags.Instance).SetValue(连接,NULL); //返回我们有光泽,新的连接。
返回storeConnection;
}
}
}
我这一情况报告给小型探查队(HTTP://$c$c.google.com/p/mvc-mini-profiler/issues/detail ?ID = 62&安培;可= 1),他们已经发出今天这似乎解决该问题的补丁。
。我想这将被包含在下一版本中。希望帮助:)
I have been playing around with MVC-Mini-Profiler, and found it very useful. However, on all pages I trace on, I get reports of duplicate queries, like the one below.
However, I have traced the queries in SQL Server Profiler, and there is not doubt it only hits the DB once.
Am I missing a concept here or have I set it up the wrong way? I have searched high and low for people with similar problems, with no luck, so I doubt there is a bug.
http://localhost:27941/clubs
T+175.2 ms
Reader
13.6 ms
utePageHierarchy Execute System.Collections.Generic.IEnumerable<T>.GetEnumerator GetResults Execute ExecuteStoreCommands
SELECT
[Extent1].[TeamId] AS [TeamId],
[Extent1].[Title] AS [Title],
[Extent1].[TitleShort] AS [TitleShort],
[Extent1].[LogoImageId] AS [LogoImageId],
[Extent1].[Slug] AS [Slug],
(SELECT
COUNT(1) AS [A1]
FROM [dbo].[Athletes] AS [Extent2]
WHERE [Extent1].[TeamId] = [Extent2].[TeamId]) AS [C1]
FROM [dbo].[Teams] AS [Extent1]
WHERE 352 = [Extent1].[CountryId]
http://localhost:27941/clubs
T+175.4 ms
DUPLICATE Reader
13.4 ms
utePageHierarchy Execute System.Collections.Generic.IEnumerable<T>.GetEnumerator GetResults Execute ExecuteStoreCommands
SELECT
[Extent1].[TeamId] AS [TeamId],
[Extent1].[Title] AS [Title],
[Extent1].[TitleShort] AS [TitleShort],
[Extent1].[LogoImageId] AS [LogoImageId],
[Extent1].[Slug] AS [Slug],
(SELECT
COUNT(1) AS [A1]
FROM [dbo].[Athletes] AS [Extent2]
WHERE [Extent1].[TeamId] = [Extent2].[TeamId]) AS [C1]
FROM [dbo].[Teams] AS [Extent1]
WHERE 352 = [Extent1].[CountryId
I use EF4 and have implemented the context like this:
public class BaseController : Controller
{
public ResultsDBEntities _db;
public BaseController()
{
var rootconn = ProfiledDbConnection.Get(GetStoreConnection(ConfigurationManager.ConnectionStrings["ResultsDBEntities"].ConnectionString));
var conn = ProfiledDbConnection.Get(rootconn);
_db = ObjectContextUtils.CreateObjectContext<ResultsDBEntities>(conn);
}
public static DbConnection GetStoreConnection<T>() where T : System.Data.Objects.ObjectContext
{
return GetStoreConnection("name=" + typeof(T).Name);
}
public static DbConnection GetStoreConnection(string entityConnectionString)
{
DbConnection storeConnection;
// Let entity framework do the heavy-lifting to create the connection.
using (var connection = new EntityConnection(entityConnectionString))
{
// Steal the connection that EF created.
storeConnection = connection.StoreConnection;
// Make EF forget about the connection that we stole (HACK!)
connection.GetType().GetField("_storeConnection",
BindingFlags.NonPublic | BindingFlags.Instance).SetValue(connection, null);
// Return our shiny, new connection.
return storeConnection;
}
}
}
I reported this to the Mini Profiler team (http://code.google.com/p/mvc-mini-profiler/issues/detail?id=62&can=1) and they've issued a patch today which appears to fix the issue.
I imagine this will be included in the next release. Hope that helps :)
这篇关于MVC-迷你探查显示错误重复查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!