2
我在NHibernate的(使用标准)的HQL查询字符串NHibernate的查询(HQL VS标准)
from MyTable table
where table.StartTime + table.Duration >= : startTime
and table.MyId = : id
我怎么能写这个的HQL没有?
我在NHibernate的(使用标准)的HQL查询字符串NHibernate的查询(HQL VS标准)
from MyTable table
where table.StartTime + table.Duration >= : startTime
and table.MyId = : id
我怎么能写这个的HQL没有?
This可能对DateTime + TimeSpan问题感兴趣。
这工作你的情况:
QueryOver:
int id = 1;
DateTime startTime = DateTime.Now.AddDays(5.0);
var vacations = session.QueryOver<Vacation>()
.Where(v => v.Employee.Id == id)
.And(v => v.StartDate > startTime
|| (v.StartDate == startTime.Date && v.Duration >= startTime.TimeOfDay))
.List();
的ICriteria:
var vacationsCrit = session.CreateCriteria(typeof(Vacation))
.Add(Expression.Eq("Employee.Id", id))
.Add(Expression.Disjunction()
.Add(Expression.Gt("StartDate", startTime))
.Add(Expression.Conjunction()
.Add(Expression.Eq("StartDate", startTime.Date))
.Add(Expression.Ge("Duration", startTime.TimeOfDay))))
.List();
双方将输出完全一样的SQL。应该提到,你不能这样做,如上面的链接所述:
var vacations = session.QueryOver<Vacation>()
.Where(v => v.Employee.Id == id)
.And(v => v.StartDate.Add(v.Duration) >= startTime) // <-- this will NOT work
.List();
Thansk为您的简要回答... name @ Florian Lim – NoviceAndNovice 2011-03-17 10:43:22