好的,我在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))
答案 0 :(得分:0)
您可以使用let
关键字
var availableBunks = from bunk in bunks
let bl = from bookingLine in bookingLines
where bookingLine.Date == DateTime.Today.AddDays(d)
select bookingLine.BunkId
where bunk.Gender == "F" && !bl.Contains(bunk.BunkId)
select bunk;