我有一个数据库,其中包含两个表FirstTable
和SecondTable
"。还有一个视图CustomView
。 CustomView
从表FirstTable
和SecondTable
中获取值。
在我的edmx中,我将视图映射到我的模型中。我从数据库中获取数据,工作正常。但是,如果我尝试更新我收到的任何数据DbUpdateException
。
这是我的代码,
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();
}
}
以下是例外,
{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()
如果我映射表FirstTable
并更新其值,它可以正常工作,但是对于视图,它会失败。