안녕 메신저 -LINQ, 하나가 아닌 DB를 호출을 세
public int GetUserPoints(string userName)
{
int? postPoints = db.Posts.Where(p => p.Aspnet_User.UserName == userName).Sum(b => (int?)b.UpVotes);
int? eventPoints = db.Events.Where(p => p.Aspnet_User.UserName == userName).Sum(b => (int?)b.UpVotes);
int? commentPoints = db.Comments.Where(p => p.Aspnet_User.UserName == userName).Sum(c => (int?)c.UpVotes - (int?)c.DownVotes);
return (postPoints.HasValue ? postPoints.Value : 0) + (eventPoints.HasValue ? eventPoints.Value : 0) + (commentPoints.HasValue ? commentPoints.Value/5 : 0);
}
을 나는 이것을 달성하기 위해 3 개의 별도 db 호출을한다. 내가 이것을 하나 할 수 있을까?
그냥 팁 :'postPoints ?? 0'' 대신'(postPoints.HasValue? postPoints.Value : 0)' –