简体   繁体   English

与linqdatasource的加入语句

[英]joining statement with linqdatasource

how can I make this sql query works with linqdatasource? 如何使此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

I've read this answer but I couldn't understand the syntax used by linqdatasource join statement. 我已经读过这个答案,但是我不明白linqdatasource join语句使用的语法。 any help would be great. 任何帮助都会很棒。

With a LinQ statement it should look something like following code. 使用LinQ语句,它应类似于以下代码。 Please mind that this is written out of my head and not tested. 请注意,这是我写的,未经测试。 It's a mere indication of how it should look, not a working solution. 这仅是其外观的指示,而不是有效的解决方案。

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

Hope this gets you on the way. 希望这能帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM