0
我有一個sql
這樣的查詢:SQL到LINQ轉換失敗
select attendance.intime, attendance.outtime, attendance.date, employees.name from employees left join attendance on employees.id = attendance.employeeid where attendance.date = '12/12/2016'
我想將其轉換爲LINQ
方法的語法。我試過這個。
var attendances = db.Attendances.Include(a => a.Admin).Include(a => a.Employee);
var employees = db.Employees.Include(a => a.Admin);
var linq_query = attendances
.Join(
employees,
a => a.EmployeeId,
e => e.Id,
(a, e) => new { e.Name, a.InTime, a.OutTime, a.Date
})
.Where(e=> e.Date == DateTime.Parse("12/12/2016"));
但它給我500內部服務器錯誤。在哪裏改變?
500錯誤可能是很多很多事情。你有調試器的'InnerException'嗎? – G0dsquad
通過刪除'.Where()',不顯示500內部錯誤。而且它也是'INNER JOIN'而不是'LEFT JOIN'的結果.. –
如果你知道日期,爲什麼不使用實際的DateTime對象而不是解析?例如使用'new DateTime(2016,12,12)'。否則,你肯定會遇到解析錯誤 - 在你的服務器的語言環境*中寫入12月13日的正確方法是什麼? –