I have a database which consists of two tables FirstTable
and SecondTable
". And there is a View CustomView
. CustomView
gets values from both tables FirstTable
and SecondTable
.
In my edmx, I mapped view into my model. I am getting data from the database which works fine. But if I try to update any data I am getting DbUpdateException
.
Here is my code,
public UpdateData(string something)
{
using (var database = new MyDatabase())
{
var records = database.Context.CustomView.ToList();
foreach (var record in records)
{
database.Context.CustonView.Attach(record);
record.Something = something;
}
database.Context.SaveChanges();
}
}
Here is the exception,
{System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> iAnywhere.Data.SQLAnywhere.SAException: Syntax error near 'set' on line 16
at iAnywhere.Data.SQLAnywhere.SACommand.ExecuteNonQuery()
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
at System.Data.Entity.DbContext.SaveChanges()
If I map table FirstTable
and update its values, it is working fine, but for view it fails.