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