I want to make a class that joins Table
and ObservableCollection
functionality. So I wrote:
public sealed class ObservableTable<T> : ObservableCollection<T>, ITable<T> where T : class
{
private Table<T> _table;
public Expression Expression => _table.AsQueryable().Expression;
public Type ElementType => _table.AsQueryable().ElementType;
public IQueryProvider Provider => _table.AsQueryable().Provider;
public new IEnumerable<T> Items => _table;
public new T this[int index] => _table.ElementAt(index);
public new int Count => _table.Count();
public ObservableTable(ref DataContext dbContext)
{
_table = dbContext.GetTable<T>();
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public void InsertOnSubmit(T entity)
{
_table.InsertOnSubmit(entity);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add));
}
public void Attach(T entity)
{
_table.Attach(entity);
}
public void DeleteOnSubmit(T entity)
{
_table.DeleteOnSubmit(entity);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove));
}
}
But despite _table
object properly gets all the records from database, when I cast my class as ObservableCollection
the collection is empty. What should I override to get it working? Aren't Items
and Count
properties enough?