私は
ObservableCollection<TEntity>
EF7では、
DbSet<TEntity>.Local
存在していないようです。
回避策はありますか?
現在のバージョンのEntityFramework(RC1-final)にはDbSet.Local機能はありません。しかし!あなたは現在の拡張メソッドと同様の何かを達成することができます:
public static class Extensions
{
public static ObservableCollection<TEntity> GetLocal<TEntity>(this DbSet<TEntity> set)
where TEntity : class
{
var context = set.GetService<DbContext>();
var data = context.ChangeTracker.Entries<TEntity>().Select(e => e.Entity);
var collection = new ObservableCollection<TEntity>(data);
collection.CollectionChanged += (s, e) =>
{
if (e.NewItems != null)
{
context.AddRange(e.NewItems.Cast<TEntity>());
}
if (e.OldItems != null)
{
context.RemoveRange(e.OldItems.Cast<TEntity>());
}
};
return collection;
}
}
注:より多くのデータを照会すると、リストは更新されません。それは変更トラッカーに戻ってリストの変更を同期します。