我正在使用bellow sql获取可用空间:
select rooms.number
from rooms
EXCEPT
(SELECT rooms.number
FROM dbo.Bookings
INNER JOIN dbo.Rooms ON Extent1.RoomId = dbo.Rooms.Id
WHERE
(Bookings.StartDate <= '2014-12-01')
AND (Bookings.EndDate >= '2016-12-05')
)
你能帮我转换成Linq吗? (比如&#34; var list =来自db ......&#34;
提前致谢
答案 0 :(得分:0)
试试这个:
var start = DateTime.ParseExact("20141201",
"yyyyMMdd",
CultureInfo.InvariantCulture);
var end = DateTime.ParseExact("20141205",
"yyyyMMdd",
CultureInfo.InvariantCulture);
var list = dbContext.Rooms
.Except(dbContext.Bookings
.Where(e => e.StartDate >= start)
.Where(e => e.EndDate <= end)
.Select(e => e.Room))
.SELECT(e => e.Number)
.ToList();