SUM(CASE WHEN [dbo].[tblHits].IsLike = 1 THEN 1 ELSE 0 END) as Likes
我想要这样的事情,下面的代码给我错误
不能隐式转换类型bool?小数?
TotalLikes = grouped.Sum(d => d.IsLike == true ? d.IsLike = true : d.IsLike = false )
答案 0 :(得分:1)
最直接的翻译是:
TotalLikes = grouped.Sum(d => d.IsLike == true ? 1 : 0)
可以缩短为:
TotalLikes = grouped.Sum(d => d.IsLike ? 1 : 0)
但我会用:
TotalLikes = grouped.Count(d=>d.IsLike);