SQL / Linq连接两个表并将日期和时间连接到单个查询中

时间:2015-03-09 22:10:30

标签: c# sql linq

我有两个表格如下所示。 SessionBooking.Date是Date字段,TimeSlot.StartTime是Time字段。

表架构:

enter image description here

您可以看到下面的当前查询我正在成功加入两个表但是我需要将日期和开始时间加入单个“Datetime”字段,以便我可以按日期时间(当前日期和时间)排序

我该怎么做呢,以及如何用Linq to SQL编写。

我到目前为止(不包括加入)

List<SessionBooking> bookings = db.SessionBookings.Where(m => m.MemberId == this.Id && m.LocationId == this.HomeLocationId && m.Date >= currentDate).OrderByDescending(m => m.Date).ThenBy(m => m.TimeSlot.StartTime).Take(limit).ToList();

enter image description here

1 个答案:

答案 0 :(得分:-1)

尝试类似SELECT a.Date + b.time

的内容

FROM [eMart]。[dbo] .sessionBooking as a       join Timeslot as b on a.id = b.id

相关问题