In this case, I would say that conditional operator ( p ? x : y) is a good replacement.
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 Whereand Sum:
Jan = grp.Where(x => x.Month == 1).Sum(x => x.Days),
I'm not sure if these SQL translate accurately, but they should have the same result.
source
share