tags:

views:

40

answers:

1

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"

A: 

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>;
      }
arame3333