简体   繁体   中英

joining statement with linqdatasource

how can I make this sql query works with 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. any help would be great.

With a LinQ statement it should look something like following code. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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