I'm new to NHibernate and trying to create my first mapping.
I have created a class like this (my example is simplified):
public class Buyer
{
public int BuyerID { get; set; }
public string Name { get; set; }
public decimal AverageOrderAmount { get; private set; }
public DateTime LastOrderDate { get; private set; }
}
Normally, to get this data out of SQL Server, I would write a query using aggregate functions like this:
select b.BuyerID, b.Name,
avg(o.OrderTotal) as AverageOrderAmount, max(o.OrderDate) as LastOrderDate
from Buyers b
join Orders o on o.BuyerID = b.BuyerID
where BuyerID=@BuyerID
group by b.BuyerID, b.Name
My question is, how do I communicate this in my mapping? Is this possible?
I supposed I could store these calculated values in the Buyers cable and recalculate them as needed, but that doesn't feel right.