c# - Entity Framework calculated property -
i have following classes in ef6
items ------------- public int itemid public string itemname public decimal itemprice public virtual list<listpricesitems> listpricesitems public decimal itemdiscountedprice (need calculate this) listprices ---------------- public int listid public string listdescription public date listvaliduntildate listpricesitems ----------------- public int lprid public int listid public int itemid public decimal itemdiscountedprice
what need have itemdiscountedprice in items following
[notmapped] public decimal itemdiscountedprice { { if(listpricesitems.listprices.listvaliduntildate > date.now()){ return listpricesitems.itemdiscountedprice ?? itemprice; } } }
is possible ? if discount policy still active, check if itemdiscountedprice null , give standard itemprice if null.
updated
public partial class items { [key] [databasegenerated(databasegeneratedoption.none)] public int itemid { get; set; } public string itemname { get; set; } [column(typename = "money")] public decimal? itemprice { get; set; } public virtual icollection<listpricesitems> listpricesitems { get; set; } [notmapped] public decimal itemdiscountedprice { { return ...................... } } } public partial class listprices { [key] public int listid { get; set; } public string listdescription { get; set; } [column(typename = "datetime2")] public datetime? listvaliduntildate { get; set; } public virtual icollection<listpricesitems> listpricesitems { get; set; } } public partial class listpricesitems { [key] public int lprid { get; set; } public int? listid { get; set; } public int? itemid { get; set; } [column(typename = "money")] public decimal? itemdiscountedprice { get; set; } public virtual listprices listprices { get; set; } }
Comments
Post a Comment