문제

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.

도움이 되었습니까?

해결책

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top