如何使这个SQL查询与linqdatasource一起使用?
select tbl_WeekDays.WeekDay, tbl_DayTimes.TimeFrom, tbl_DayTimes.TimeTo from tbl_WeekDays
left join tbl_DayTimes on tbl_DayTimes.WeekDayId = tbl_WeekDays.WeekDayId
where tbl_WeekDays.classID = @id
我已阅读this回答,但我无法理解linqdatasource join语句使用的语法。任何帮助都会很棒。
答案 0 :(得分:0)
使用LinQ语句,它应该类似于以下代码。请注意,这是写在我脑海中而未经过测试。它只是表明它应该是什么样子,而不是一个有效的解决方案。
//Change following variables accordingly
var ctx = new YourDbContext();
var id = 3;
from tblWeekDays in ctx.WeekDays
join tblDayTimes in ctx.DayTimes
on tblWeekDays.WeekDayId == tblDayTimes.WeekDayId
where tblWeekDays.classID == id
select new
{
WeekDay = tblWeekDays.WeekDay,
TimeFrom = tblDayTimes.TimeFrom,
TimeTo = tblDayTimes.TimeTo
};
希望这能让你顺利上路。