What I want to do is display a simple grid of data which contains the entity data, and the aggregate data of its children. For example lets use a Order and line items. I wan
Given:
public class Order
{
public virtual int OrderId {get; set;}
public virtual DateTime OrderDate {get; set;}
public virtual IList<LineItem> LineItems {get; set;}
}
public class LineItem
{
public virtual int Id {get; set;}
public virtual string Description {get; set;}
}
To query a projection of Order + Aggregated LineItem using QueryOver API you can do the following:
OrderDto orderDto = null;
LineItem items = null;
var results = session.QueryOver<Order>()
.JoinAlias(o => o.LineItems, () => items)
.Select(Projections.ProjectionList()
.Add(Projections.Property<Order>(o=>o.Id).WithAlias(()=>orderDto.OrderId))
.Add(Projections.Property<Order>(o=>o.DateOrdered).WithAlias(()=>orderDto.DateOrdered))
.Add(Projections.Count(()=> items.Id).WithAlias(()=>orderDto.ItemCount))
)
.TransformUsing(Transformers.AliasToBean<OrderDto>())
.List<OrderDto>();