今天領導反饋一個線上的查詢很慢,要我查找原因。
查看代碼分析應該是SQL 查詢導致,后來發現是Linq 寫的。
第一次接觸Linq查詢轉Sql,后來今天查資料和咨詢別人,發現了一個可行的方法
源碼:
var list= from a in tableA join b in tableB on a.Id equals b.AId from c in tableC.Where(x => x.AId == c.Id).DefaultIfEmpty() where dispatch == null && a.StatusId == 1
方法: var list= from a in tableA join b in tableB on a.Id equals b.AId from c in tableC.Where(x => x.AId == c.Id).DefaultIfEmpty() where dispatch == null && a.StatusId == 1
var sql=list.toString();