I am using EF and have a model entity Test.cs which contains several properties and a computed property Deviation. This property should be displayed in the gridview, but no updates should happen on this property. I have defined the computed column as following:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public decimal? Deviation { get; private set; }
In the controller method, I'll try to save the changes the following way:
public virtual ActionResult BatchUpdate(MVCxGridViewBatchUpdateValues<T, int> updateValues)
{
if (ModelState.IsValid)
{
var model = Db.Set<T>();
// update existing records updateValues.Update.Where(updateValues.IsValid).ForEach(updateValue => UpdateModel(model.Single(e => e.Id == updateValue.Id), null, null, excludeProperties: new[] { "Deviation" }));
// apply changes
Db.SaveChanges();
}
else
{
throw new Exception("Model is invalid");
}
return GridViewPartial();
}
Even though I exclude the computed property Deviation, I get the following exception:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Invalid column name 'Deviation'.
Any idea what I'm doing wrong here?
Thanks in advance.