Question

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.

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top