3

I have a DTO class like this:

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; } }
}

And I have a projections list like this:

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),
};

and transforms query with query.Select(projections.ToArray()).TransformUsing(Transformers.AliasToBean<Aggregates>();

In runtime TransformUsing() throws an Exception:

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

This is quite expected, because of NHibernate select the name of the property from a member expression (without leading member access). So, how can I setup projections, which will fill in property of property Aggregates class?

  • Maybe check this: http://stackoverflow.com/a/24248309/1679310 and this http://stackoverflow.com/a/26901453/1679310 – Radim Köhler Apr 07 '15 at 07:59
  • 1
    thx, @RadimKöhler. I use your DeepTransformer with some improvements: replace `IResultTransformer` to `AliasedTupleSubsetResultTransformer`, add method `IsTransformedValueATupleElement` which always return false and method `IList TransformList(IList collection)` always return collection. This changes allows use DeepTransformer to transform collections. – VitaliyLitvinyuk Apr 07 '15 at 09:36

0 Answers0