I'm using Entity Framework "Code First" approach in a ASP.NET MVC 3 web application. In my database I have several computed columns. I need to use these columns to display data (which works fine).
However when I come to insert rows into this table, I'm getting the following error:
The column "ChargePointText" cannot be modified because it is either a computed column or is the result of a UNION operator.
Is there a way to mark the property as readonly in my class?
public class Tariff
{
public int TariffId { get; set; }
public int Seq { get; set; }
public int TariffType { get; set; }
public int TariffValue { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int ChargePoint { get; set; }
public string ChargePointText { get; set; }
}
I've found the solution. Entity Framework provides a data annotation called DatabaseGenerated. Use it like this:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string ChargePointText { get; set; }
Get more details here: http://msdn.microsoft.com/en-us/library/gg193958.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With