好的,我在 LinqPad 中测试过的这个 LINQ 语句有一个错误,它工作正常。错误是:
无法创建“HostelApp.Models.bookingLines”类型的常量值。此上下文仅支持原始类型或枚举类型。
代码在这里:
var availableFBunks = from b in this.bunks
where b.gender == "F" &&
!this.bookingLines.Any(
l => (l.bunkID == b.bunkID) && (l.date == DateTime.Today.AddDays(i)))
select b;
SQL 语句:
-- Region Parameters
DECLARE @p0 NVarChar(1000) = 'F'
DECLARE @p1 DateTime = '2013-11-07 12:00:00 AM'
-- EndRegion
SELECT b.bunkDesc AS Bunk_Name
FROM bunks AS b
WHERE (gender = @p0) AND NOT EXISTS
(SELECT *
FROM bookingLines AS l
WHERE l.bunkID = b.bunkID and (l.date = @p1))