【发布时间】:2016-07-12 13:47:05
【问题描述】:
我在我的 SQL Server 数据库中将日期和时间都保存为DateTime,并且我的映射中有一个DateTime 属性。在我的查询中,我需要单独访问日期和时间。使用日期我没有问题,但是当尝试从 DateTime 获取时间时,我收到以下错误:
附加信息:无法解析属性:TimeOfDay of:IWS.DataContracts.ServicesPlanning
在其他属性中节省时间不是我想要的,即使我尝试过也无法让它发挥作用。
使用QueryOver查询:
Session.QueryOver<ServicesPlanning>()
.JoinAlias(x => x.TeamMember, () => stm)
.Where(() => stm.Id == _memberId)
.Where(x => (x.AllDay && (x.StartDate == _startDate && x.EndDate == _endDate)) ||
(!x.AllDay && x.StartDate.Date == _startDate && x.EndDate.Date == _endDate
&& (x.StartDate.TimeOfDay > _endTime.Value || x.EndDate.TimeOfDay < _startTime.Value)))
.RowCount() > 0;
使用 LINQ 查询:
return Session
.Query<ServicesPlanning>()
.Where(x => x.TeamMember.Id == _memberId)
.Any(x => (x.AllDay && (x.StartDate.Date == _startDate && x.EndDate.Date == _endDate)) ||
(!x.AllDay && x.StartDate.Date == _startDate && x.EndDate.Date == _endDate && (x.StartDate.TimeOfDay > _endTime.Value || x.EndDate.TimeOfDay < _startTime.Value)));
查询目的:检查是否已经有与此日期或时间的计划,以免我们有重叠。
非常感谢任何帮助!
【问题讨论】:
-
你试过用 LINQ 代替 QueryOver 吗?
-
@PhilDegenhardt 是的,但我似乎遇到了同样的错误。我也会在上面发布我的 LINQ 查询。
标签: c# asp.net nhibernate nhibernate-mapping queryover