【发布时间】:2012-11-27 13:30:44
【问题描述】:
我在 SO 上引用了这个问题:
Store read-only calculated field with 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 列表,我想根据状态获取所有佣金的总数。也许将其存储在不同的模型中?需要一些实施建议。
【问题讨论】:
标签: c# entity-framework ef-code-first calculated-columns