I have an enumeration of type int in my entity, UserStatus.
I want to get all users where the UserStatus <> Cancelled.
So:
Session.CreateCriteria(typeof(User))
.Add(Expression.Eq("UserStatus", (int)UserStatus.Cancelled)
.UniqueResult<User>();
The above is fore equal, I need to get not equal.
With thanks to Alex use this for NH2 and up:
Session.CreateCriteria(typeof(User))
.Add(Restrictions.Not(Restrictions.Eq("UserStatus", (int)UserStatus.Cancelled))
.UniqueResult<User>();
For older Versions this would be:
Session.CreateCriteria(typeof(User))
.Add(Expression.Not(Expression.Eq("UserStatus", (int)UserStatus.Cancelled))
.UniqueResult<User>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With