我想刷新我的所有实体DbContext
而不重新创建它,我尝试了以下方法,但它们都没有意义:
var context = ((IObjectContextAdapter)myDbContext).ObjectContext;
var refreshableObjects = (from entry in context.ObjectStateManager.GetObjectStateEntries(
EntityState.Added
| EntityState.Deleted
| EntityState.Modified
| EntityState.Unchanged)
where entry.EntityKey != null
select entry.Entity);
context.Refresh(RefreshMode.StoreWins, refreshableObjects);
//.......................................................................
foreach (var entry in this.Orm.ChangeTracker.Entries())
{
entry.State = EntityState.Unchanged;
}
this.Orm.ChangeTracker.DetectChanges();
唯一让我耳目一新的DbContext
:
foreach (var i in this.Orm.ChangeTracker.Entries())
i.Reload();
但是太慢了。你能帮我选择正确的方法吗?