【发布时间】:2013-07-28 09:27:33
【问题描述】:
我正在通过将现有实体附加到我的数据上下文来更新它,如下所示:
var updatedDocumentState = new AccDocumentState()
{
Id = accDocumentState.Id,
IsDocumentary = accDocumentState.IsDocumentary,
IsEditable = accDocumentState.IsEditable,
IsRecursive = accDocumentState.IsRecursive,
Title = accDocumentState.Title,
Reportable = accDocumentState.Reportable,
};
context.AccDocumentStates.Attach(updatedDocumentState);
context.ObjectStateManager.ChangeObjectState(updatedDocumentState, System.Data.EntityState.Modified);
flag = context.SaveChanges() > 0;
这可行,但是在保存附加实体后,我没有更新但我想保持原样的现有实体的属性被覆盖并赋予空值。如何附加我的实体并保留我尚未更新的现有实体的属性?
【问题讨论】:
-
一个问题,您创建的实体是现有实体还是新实体(从数据库的角度来看)?
-
它是一个现有的实体
标签: c# entity-framework entity-framework-5