Using a NHibernate QueryOver expression, how can I compare against a local variable?
For example:
[DB Table]
1 - 01/01/2011
2 - 02/20/2011
3 - 03/09/2011
I want a query to look like:
SELECT * FROM Table WHERE '03/01/2011' >= DateColumn
Where '03/01/2011' is a variable I'm passing in.
I tried:
DateTime myDate = new DateTime(2011, 3, 1);
QueryOver.Of<Table>(() => tAlias).Where(() => myDate >= tAlias.DateColumn)
However, this throws the following exception:
Could not find property myDate
Any ideas how to do this using a QueryOver expression?
I've never tried using Where with an parameterless expression, what if you tried something like this (what I'd use if I were doing a QueryOver[Table], not sure if there is a difference with .Of[Table])?
.Where(r => r.DateColumn <= myDate)
All the examples I've seen use the constant on the right side of the expression too, not sure if there's anything to that ( edit: looking at Phill's comment above, it appears that NHibernate does expect the column on the left and the value on the right).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.