現在の週に報告された合計時間の合計を返すクエリがあります。以下のコードは、正しい総時間数を返しますが、データベース内の特定のユーザーについては返しません。
public int reportedWeekTime(int currentWeek, string username)
{
var totalTime = (from u in context.Users
from r in context.Reports
from w in context.Weeks
from d in context.Days
where u.Id == r.UserId && r.weekNr.Equals(currentWeek) && r.Id == w.ReportId && w.DayId == d.Id
select d.Hour).DefaultIfEmpty(0).Sum();
return totalTime;
}
最初のメソッドは 24 という数字を返します。これは正しいですが、私が言ったように、特定のユーザーに対してではありません。
私はこれをやろうとしていますが、見返りに0が返されます。私は何を間違っていますか?
public int reportedWeekTime(int currentWeek, string username)
{
var totalTime = (from u in context.Users
from r in context.Reports
from w in context.Weeks
from d in context.Days
where u.Id == r.UserId && r.weekNr.Equals(currentWeek) && r.Id == w.ReportId && w.DayId == d.Id && u.Username.Contains(username)
select d.Hour).DefaultIfEmpty(0).Sum();
return totalTime;
}