daniel
daniel

Reputation: 35703

Executing a method everytime an item is added to a collection

i want to execute a method each time an item is added to an DbSet.

Is this possible without calling this method seperate each time?

Upvotes: 2

Views: 136

Answers (1)

Dutts
Dutts

Reputation: 6191

DbSet has a property "Local" which is an ObservableCollection. You can subscribe to CollectionChanged on this to see when things have been added.

So something like:

this.ttActivities.Local.CollectionChanged += ttActivitiesChanged;


public void ttActivitiesChanged(object sender, NotifyCollectionChangedEventArgs args) 
{
  if (args.Action == NotifyCollectionChangedAction.Add)
  {
    // Something has been added
  }
}

Upvotes: 1

Related Questions