CodeGo.net> Linq to SQL与分组依据

我正在尝试将此T-SQL转换为Linq To SQL,但无法通过聚合函数计算出该组.任何帮助欢迎.

select c.ClientID, GivenName, Surname, max(a.Address), max(t.Value)
from Client c
left join ClientAddress a on c.ClientID = a.ClientID
left join ClientContact t on c.ClientID = t.ClientID
group by c.ClientID, GivenName, Surname

解决方法:

要按组合键分组,通常使用匿名类型:

    var qry = from x in someSource
              group x by new { x.ClientID, x.GivenName, x.Surname } into grp
              select new { grp.Key, Address = grp.Max(x => x.Address),
                  Value = grp.Max(x => x.Value) };
上一篇:SSIS 数据类型 第二篇:变量的数据类型


下一篇:c#-与多个条件存在的Linq查询等效