我在 SO 上引用了这个问题:
使用 Entity Framework Code First 存储只读计算字段
他们所做的事情是有道理的,但我正在尝试一些不同的东西,并且不确定我的实现是否正确,或者是否有更简单的方法来做到这一点:
public class AffiliateCommission
{
public int Id { get; set; }
public Merchant Merchant { get; set; }
public AffiliateCommissionType Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int Amount { get; set; }
public string Status { get; set; }
public DateTime RecievedDate { get; set; }
public int TotalPaid { get
{
if (Status == "Paid")
{
return this.Amount += this.Amount;
}
return 0;
}
protected set { }
}
public int TotalUnpaid
{
get
{
if (Status == "Unpaid")
{
return this.Amount += this.Amount;
}
return 0;
}
protected set { }
}
public int TotalInvoiced
{
get
{
if (Status == "Invoiced")
{
return this.Amount += this.Amount;
}
return 0;
}
protected set { }
}
}
将有一个 AffiliateCommissions 列表,我想根据状态获得所有佣金的总数。也许将它存储在不同的模型中?需要一些实施建议。