Linq查询比SQL执行查询花费的时间太长

时间:2018-11-23 11:19:22

标签: c# linq

我们正在将后端sql逻辑移至前端,并且将前端sql作为前端C#中的Linq查询进行处理。它工作正常,但执行查询所需的时间比sql长。下面是我的代码供您参考,

objTypeDefLst = (from t1 in objTypeDefLst
                                     join t2 in objTypeDefLst
                                         on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
                                     where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
                                     orderby (t1.TypeDefDesc == "Successful" && t1.TypeDefGroup == "ResponseType" ? 1 : 
                                     (t1.TypeDefDesc == "Failed" && t1.TypeDefGroup == "ResponseType" ? 2 : 
                                     (t1.TypeDefDesc == "Failed Attempt" && t1.TypeDefGroup == "ResponseType" ? 3 : 4)))
                                     select new TypeDefinition
                                     {
                                         ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
                                         ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
                                     }).ToList(); 

1 个答案:

答案 0 :(得分:0)

TUtil.CheckInt(t2.ParentId, 0)更改辅助功能string.IsNullOrEmpty(t2.ParentId) ? 0 : Convert.ToInt32(t2.ParentId)后,它的工作速度更快。