C# LinQ 左聯接加分組聚合查詢
阿新 • • 發佈:2017-07-12
select peid pen join ble blog logs key 聚合
真是醉了,前段時間摸索半天今天一寫又忘了,特此寫下來備忘,望大嬸指點
from a in Table1 join b in Table2 on a.Id equals b.Id2 into e from f in e.DefaultIfEmpty() group new { a.Id1, a.Name, f.id2 } by new { a.Id,//一表的ID a.Name,//一表的字段(Name) f.id2//二表的字段(type) } into c select new Sontypes { TypeId = c.Key.Id, TypeName = c.Key.Name, TaltoNumber = c.Key.id2 == null ? 0 : c.Count()//這裏判斷二表有沒數據,沒有數據返回0,有數據返回總量 }
看來以後要多多記筆記了,尷尬
C# LinQ 左聯接加分組聚合查詢