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 のリストが作成される予定で、ステータスに基づいてすべてのコミッションの合計を取得したいと考えています。おそらく別のモデルに保存しますか?実装に関するアドバイスが必要です。