使用StackExchange.Profiling.MiniProfiler
该类以将 Linq-To-Sql 用作 ORM 来分析 ASP.NET MVC 应用程序。
我正在尝试将一项操作减少为一个 SQL,以便不再有任何重复项。所以我相应地更改了我的 linq-to-sql 代码,但它对速度没有任何积极影响。
然后我检查了 SQL 所需的时间。
这显示了 MiniProfiler:
当我在 Management Studio 中启动完全相同的 SQL 时,它的速度非常快:
这是代码:
from t in type
let tDoc = (from d in context.documents
where d.Key == t.No
&& d.RType == (int)RType.Art
&& d.AType == (int)AType.Doc
select d).FirstOrDefault(d => d.UseForThumb)
select new Time
{
Id = t.Id,
//... more simple mappings here
// then a complex one:
DocsCount = context.documents.Count(d =>
(d.Key == t.Id.ToString()
&& d.RType == (int)RType.Type
&& d.AType == (int)AType.Doc)
||
(d.Key == t.No
&& d.RType == (int)RType.Art
&& d.AType == (int)AType.Doc)),
// and another one
ThumbId = (tDoc != null && tDoc.FRKey.HasValue) ? tDoc.FRKey.Value : 0
};
造成巨大差异的原因是什么?-编辑:没有区别,我只是误解了 SSMS :(
无论如何,我的问题仍然存在。我可以改变什么以使其更快?
我有时读到 Linq-To-Sql 的映射存在性能问题。有没有办法解决这个问题?