我无法使用以下查询。分组和总和没有问题,但是当我尝试进行条件求和时,我在编译器上收到以下错误:
Error CS1503 Argument 1: cannot convert from 'NHibernate.Criterion.IProjection' to 'System.Linq.Expressions.Expression<System.Func<ManagementWebBase.Models.FinancialTransaction.FinancialTransactionTO, object>>'
该功能的代码是:
var summary = session.QueryOver<FinancialTransactionTO>().Select(
Projections.Group<FinancialTransactionTO>(t=>t.Company.Id),
Projections.Sum<FinancialTransactionTO>(t=>t.Total),
Projections.Sum<FinancialTransactionTO>(
Projections.Conditional(
Restrictions.Where<FinancialTransactionTO>(f => f.Type.Id == 1),
Projections.Constant(1),
Projections.Constant(0)))).List<object>();
return summary;
我见过的所有例子都没有差异。我做错了什么?
答案 0 :(得分:0)
使用Projection.Sum解决条件部分没有类型: 这是我正在使用的工作示例:
var summary = session.QueryOver<FinancialTransactionTO>().Select(
Projections.Group<FinancialTransactionTO>(t => t.Company.Id),
Projections.Sum<FinancialTransactionTO>(t => t.Total),
Projections.Sum(
Projections.Conditional(
Restrictions.Where<FinancialTransactionTO>(f => f.Type.Id == 1),
Projections.Property<FinancialTransactionTO>(f=>f.Total),
Projections.Constant(0.0M, NHibernateUtil.Decimal)))).List<object>();
return summary;