Reputation: 2305
I've got a model being used to populate a database
public class Account
{
public int NumberOfPayPeriods { get { return 24; } }
public decimal YearAmount { get; set; }
public decimal PlanTotal
{
get { return NumberOfPayPeriods*YearAmount; }
}
}
The NumberOfPayPeriods
attribute I need to change from just a get
to a get; set;
However, when I change this, I get an EntityCommandExecutionException
(invalid column name). I assume this is because it is trying to map this to the database where there previously existed no such column (as it was only a get).
Is there any way I can change this to a get;set; without having to delete the table? There's a lot of important data on there that cannot be lost or re-created.
Upvotes: 0
Views: 54
Reputation: 2675
Add a [NotMapped]
attribute over the property you don't want stored.
public class Account
{
[NotMapped]
public int NumberOfPayPeriods { get { return 24; } set { ... } }
public decimal YearAmount { get; set; }
public decimal PlanTotal
{
get { return NumberOfPayPeriods*YearAmount; }
}
}
Upvotes: 3