Вопрос

I have requirement, wherein I have to calculate totals for cash and credit cards separately using conditional projection queries. My below code doesnt work and it gives me datatype mismatch error. Its says the true condition returns decimal and false returns currency. I am not sure why it does that as 0.0M does represent decimal. Can anybody please help me out with the query?

RefundTemplate.Criteria.SetProjection(
                        Projections.ProjectionList()

                        .Add(Projections.Sum(Projections.Conditional
                            (Restrictions.Eq("PaymentType", "CK"),
                                  Projections.Property("Gross"), Projections.Constant(0.0M))), "CashRefund")
                        .Add(Projections.Sum(Projections.Conditional
                            (Restrictions.Eq("PaymentType", "CC"),
                                  Projections.Property("Gross"), Projections.Constant(0.0M))), "CreditRefund"));
Это было полезно?

Решение

You can specify explicitly which type to use. For example:

Projections.Constant(0.0M, NHibernateUtil.Decimal)

See the documentation for the NHibernateUtil class here: http://elliottjorgensen.com/nhibernate-api-ref/NHibernate/NHibernateUtil.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top