我通过将现有实体附加到我的数据上下文来更新它,如下所示:
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;
这有效,但是在保存附加实体后,我没有更新但我想保持原样的现有实体的属性被覆盖并赋予空值。如何附加我的实体并保留我尚未更新的现有实体的属性?