3

我有一个像这样的 DTO 类:

public class Aggregates
{
    public Aggregates()
    {
        Sales = new StatisticAggregates();
        Refund = new StatisticAggregates();
    }

    public int ChecksAmount { get; set; }
    public StatisticAggregates Sales { get; set; }        
    public StatisticAggregates Refund { get; set; }    
    public int TotalAmount { get { return Sales.Amount - Refund.Amount; } }
    public double TotalPrice { get { return Sales.Price - Refund.Price; } }
}    

public class StatisticAggregates 
{
    public int Amount { get; set; }    
    public double Cash { get; set; }    
    public double Cashless { get; set; }    
    public double Price { get { return Cash + Cashless; } }
}

我有一个这样的预测列表:

Aggregates alias = null;
new List<IProjection>
{
    Projections.RowCount().WithAlias(() => alias.ChecksAmount),
    Projections.Sum(() => sale.Total.Amount).WithAlias(() => alias.Sales.Amount),    
    Projections.Sum(() => sale.Payment.Cash).WithAlias(() => alias.Sales.Cash),
    Projections.Sum(() => sale.Payment.Cashless).WithAlias(() => alias.Sales.Cashless),
    Projections.Sum(() => sale.Total.RefundAmount).WithAlias(() => alias.Refund.Amount),
    Projections.Sum(() => sale.Refund.Cash).WithAlias(() => alias.Sales.Cash),    
    Projections.Sum(() => sale.Refund.Cashless).WithAlias(() => alias.Sales.Cashless),
};

并转换查询query.Select(projections.ToArray()).TransformUsing(Transformers.AliasToBean<Aggregates>();

在运行时 TransformUsing() 抛出异常:

Could not find a setter for property 'Amount' in class 'Namespace.Domain.Services.Aggregates'

这是意料之中的,因为 NHibernate 从成员表达式中选择属性的名称(没有前导成员访问)。那么,如何设置预测,它将填充属性 Aggregates 类的属性?

4

0 回答 0