0

I am trying to filter only negative values using nhibernate projection queries. Below is my code for it

SearchTemplate RefundTemplate = new SearchTemplate();
            RefundTemplate.Criteria = DetachedCriteria.For(typeof(AirBilling), "Ab");
            RefundTemplate.Criteria.Add(NHibernate.Criterion.Expression.Eq("PaymentType", "CK"));
            RefundTemplate.Criteria.Add(NHibernate.Criterion.Restrictions.Lt("Gross",0));

Basically I am tying to get all the records from the AirBilling table that have a PaymentType CK and Gross value is less that zero. But somehow the code doesnt work. It doesnt throw any errors, but it simply wont work.

developer
  • 5,178
  • 11
  • 47
  • 72
  • what do you mean with "wont work"? it returns nothing, it returns billing with gross more than 0, what? – Ivo Jun 19 '12 at 19:48
  • by wont work I mean that it doesnt throw any errors but it doesnt filter any data either. – developer Jun 20 '12 at 14:25

1 Answers1

2

It could be because you are giving your entity an alias ("Ab"), so when you reference the properties you need to prefix them with the alias, eg: Expression.Eq("Ab.PaymentType", "CK")

try this:

SearchTemplate RefundTemplate = new SearchTemplate();
RefundTemplate.Criteria = DetachedCriteria.For(typeof(AirBilling), "Ab");
RefundTemplate.Criteria.Add(NHibernate.Criterion.Expression.Eq("Ab.PaymentType", "CK"));
RefundTemplate.Criteria.Add(NHibernate.Criterion.Restrictions.Lt("Ab.Gross",0));
Martin Ernst
  • 5,629
  • 2
  • 17
  • 14