In this case, I'd say the conditional operator (p ? x : y
) is a good substitute.
// context.MyTable is an IQueryable<MyTable>
var query = from t in context.MyTable
group t by t.Code into grp
select
new {
Code = grp.Key,
Jan = grp.Sum(x => x.Month == 1 ? x.Days : 0),
};
Or combine a Where
and a Sum
:
Jan = grp.Where(x => x.Month == 1).Sum(x => x.Days),
I'm not sure what SQL these translate to exactly, but they should both have the same result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…