我需要帮助查询吗?我有两张桌子,订房,还有其他的。表保留有列ResId、rfrom(日期时间)、rto(日期时间)、status(int)、UnitID(外键)。状态2表示已确认。我需要在请求期间获得所有空闲单元,查询只需要返回在请求期间没有确认的保留(状态==2)的单元(不存在)。我正在使用实体框架,所以应该是eSQL查询(其他选项是使用存储过程,但我希望避免这种情况)。数据库为sql 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一起做吗?实体名称与表相同。
发布于 2009-06-27 13:52:29
最后我使用了存储过程..。
发布于 2009-06-08 18:17:59
select value u from AEDMEntities.Units as u WHERE
not exists (select value r from AEDMEntities.Reservations as r
where r.Unit.unitID = u.unitID and r.status = 2 AND
(datetime '2009-7-7 00:00'between r.rfrom and r.rto
or datetime '2009-7-7 00:00' between r.rfrom and r.rto
or r.rfrom between datetime '2009-7-7 00:00'and datetime '2009-7-27 00:00'
or r.rto between datetime '2009-7-7 00:00' and datetime '2009-7-27 00:00'))
AND u.category=3这很管用。,但我不能写-1或+1来减去/添加天,就像在sql!中那样-如何实现这一点,我只需要将其参数化。单元是抽象类,它有两个派生类&应用程序&房间(每个类型的继承表),所以我只需要返回应用程序或房间,具体取决于方法输入参数,任何欢迎的想法。
https://stackoverflow.com/questions/964303
复制相似问题