【发布时间】:2009-06-08 10:46:49
【问题描述】:
我需要查询方面的帮助吗? 我有 2 张桌子预订和其他单位。 表保留有列 ResId,rfrom(datetime),rto(datetime),status(int),UnitID(foreign key)。 状态 2 表示已确认。 我需要在请求期间获取所有免费单位,查询需要仅返回在请求期间(不存在)未确认预订(状态 ==2)的单位。 我正在使用实体框架,所以它应该是 eSQL 查询(其他选项是使用存储过程,但我想避免这种情况)。数据库是 sql express 2005。 查询还应根据表单元中的值过滤单元,但这不是问题。 我可以在查询结果(多个 where 语句)上使用 linq 来做到这一点。
编辑: 此查询有效:
select * from Units where
not exists (select *
from Reservations
where Reservations.unitID = Units.unitID
and Reservations.status = 2
and (@datefrom between Reservations.rfrom and Reservations.rto-1
or @dateto between Reservations.rfrom+1 and Reservations.rto
or rfrom between @datefrom and @dateto-1
or rto between @datefrom+1 and @dateto))
and Units.category=@cat
在实体 sql 中会怎样看?我可以用 linq 做吗? 实体名称与表相同。
【问题讨论】:
标签: entity-framework datetime sql-server-2005 entity-sql