ObjectContext.Refresh()?

后端 未结 4 2018
天涯浪人
天涯浪人 2020-11-30 06:15

How to update ALL the dirty entities from the data store, and reset their changed values to the original store value?

The method ObjectContext.Refresh requires as a

4条回答
  •  一个人的身影
    2020-11-30 06:35

    We use this:

    return Context.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Deleted
    System.Data.EntityState.Modified).All(ose 
      => {
        if(ose.Entity != null)
          Context.Refresh(RefreshMode.StoreWins, ose.Entity);
          return true;
        });
    

    Where "Context" is the context to refresh. We filter by change state and entities to avoid new entities and relations.

提交回复
热议问题