开发者

Syntax error with left join on Linq query with a where clause

I hope this is easy to spot. This query has a synatx error;

public static IEnumerable<DailyTimeRecorded> GetPeriodData(
            Employee emp, DateTime startDate, DateTime endDate)
        {
            var listDTR =
                from dow in db.DayOfTheWeeks
                join dtr in db.DailyTimeRecordeds
                on dow.DayOfTheWeekId equals dtr.DayOfTheWeekId into sr
                where dtr.EmployeeId == emp.EmployeeId
                from x in sr.DefaultIfEmpty()
                select new
                {
                    DailyTimeRecordedId = x.DailyTimeRecordedId == null ? -1 : x.DailyTimeRecordedId,
             开发者_如何学运维       DayOfTheWeekId = dow.DayOfTheWeekId,
                    EmployeeId = emp.EmployeeId,
                    MorningTimeIn_HH = x.MorningTimeIn_HH == null ? 0 : x.MorningTimeIn_HH,
                    MorningTimeIn_MM = x.MorningTimeIn_MM == null ? 0 : x.MorningTimeIn_MM
                 };
          return listDTR  as IEnumerable<DailyTimeRecorded>;
      }

The syntax error is on the line; where dtr.EmployeeId == emp.EmployeeId The error I get is; "The name 'dtr' does not exist in the current context"


This is the solution!

public static IEnumerable<DailyTimeRecorded> GetPeriodData(
            Employee emp, DateTime startDate, DateTime endDate)
        {
            var listDTR =
                from dow in db.DayOfTheWeeks
                join dtr in db.DailyTimeRecordeds
                on dow.DayOfTheWeekId equals dtr.DayOfTheWeekId into sr
                from x in sr.DefaultIfEmpty()
                where x.EmployeeId == emp.EmployeeId
                select new
                {
                    DailyTimeRecordedId = x.DailyTimeRecordedId == null ? -1 : x.DailyTimeRecordedId,
                    DayOfTheWeekId = dow.DayOfTheWeekId,
                    EmployeeId = emp.EmployeeId,
                    MorningTimeIn_HH = x.MorningTimeIn_HH == null ? 0 : x.MorningTimeIn_HH,
                    MorningTimeIn_MM = x.MorningTimeIn_MM == null ? 0 : x.MorningTimeIn_MM
                 };
          return listDTR  as IEnumerable<DailyTimeRecorded>;
      }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜