このStackExchange.Profiling.MiniProfiler
クラスを使用して、ORM として Linq-To-Sql を使用して ASP.NET MVC アプリケーションをプロファイリングします。
重複がないように、1 つのアクションを 1 つの 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 からのマッピングにパフォーマンスの問題があることを読んだことがあります。これを回避する方法はありますか?