Is it possible to map a ICollection to a single entity BonusDto?
I am using the ICollection inside the Customer class to get all rows and from the rows i am calculation the Retained & PreviouslyPaid fields in a partial Bonus class that i want to map to BonusDto.
public class BonusDto
{
public virtual long CustomerId { get; set; }
public virtual decimal Retained { get; set; }
public virtual decimal PreviouslyPaid { get; set; }
}
public class Customer
{
public virtual string Firstname { get; set; }
public virtual ICollection<Bonus> Bonuses { get; set; }
}
public class CustomerDto
{
public virtual string Firstname { get; set; }
public virtual BonusDto Bonus { get; set; }
}
public partial class Bonus
{
private decimal _previouslyPaid;
public decimal PreviouslyPaid
{
get
{
if (UsedDate.HasValue)
{
_previouslyPaid += Amount;
}
return _previouslyPaid;
}
}
private decimal _retained;
public decimal Retained
{
get
{
if (!UsedDate.HasValue && DueDate > DateTime.UtcNow)
{
_retained += Amount;
}
return _retained;
}
}
}