例如,假设我正在创建或获取一些稍后计划插入、更新或丢弃的实体:
foreach (var foo in foos) {
if (foo.condition)
_myEntityCollection.Add(new Some_Entity_Type());
else
_myEntityCollection.Add(dc.Some_Entity_Types
.Where(t => t.ID == someID).FirstOrDefault());
}
当需要恢复时,我可以这样做:
// Exception gets thrown here if entity didn't exist in data context
_myEntityCollection.ForEach(t => dc.Refresh(RefreshMode.OverwriteCurrentValues, t));
我希望能够遍历_myEntityCollection
并确定该实体是我获取的实体,还是新实体。