是否有另一种方法可以对多个连接模型的结果进行分组?将每个模型选择为匿名类型然后分组有效,但我不知道这是正确的做法。
所有条件都在IQueryables
我在此查询之外设置的三个中:attrDatas, dataIds, and filterIds
.
var query = (
from a in attrDatas
join d in dataIds
on a.Id equals d.Id
join f in filterIds
on new { a.Id, a.AltId } equals new { f.Id, f.AltId }
select new
{
ad = a,
di = d,
//fi = f,
}
into grouped
group grouped by grouped.ad.AltId into g
select new VwModel
{
AltId = g.Key,
MaxReturn = g.Max(z => z.ad.Return),
PriceUsd = g.Max(z => z.ad.Price),
ApproxVal = g.Sum(z => (z.ad.Price*z.ad.Shares)),
HoldDate = g.Max(z => z.di.HoldDate),
});