entity framework7中是否存在DbSet .Local等效项?

我需要一个

ObservableCollection 

在EF7中,

 DbSet.Local 

似乎不存在;

有没有解决方法?

当前版本的EntityFramework(RC1-final)没有DbSet.Localfunction。 但! 你可以用当前的扩展方法实现类似的东西:

 public static class Extensions { public static ObservableCollection GetLocal(this DbSet set) where TEntity : class { var context = set.GetService(); var data = context.ChangeTracker.Entries().Select(e => e.Entity); var collection = new ObservableCollection(data); collection.CollectionChanged += (s, e) => { if (e.NewItems != null) { context.AddRange(e.NewItems.Cast()); } if (e.OldItems != null) { context.RemoveRange(e.OldItems.Cast()); } }; return collection; } } 

注意:如果您查询更多数据,它将不会刷新列表。 它会将列表中的更改同步回更改跟踪器。