0

I'm using vb.net, EF 6. I have a datagridview bound to a Bindingsource, Bindingsource's datasource is filled like this:

Mybindignsource.DataSource = (from t in context.mobj1s select t).ToList();

Now, the user can delete a record using a button with this code :

MyBindingsource.RemoveAt(index)

After that, I want to give the user the possibility to undo the deletion (and also other changes that he has made on other records).

Currently, I'm reading again from the database with the same code as above, but I'm asking if there is another method without reading the database again.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Adriano
  • 57
  • 1
  • 9
  • So your `DataSource` is a `List` that you don't have a reference to, so you can't really *undo* anything because you aren't keeping track of any of the items. – Erik Philips Dec 05 '18 at 21:26
  • Additionally to Erik's comment, since you are removing items from local list, there is nothing related to Entity Framework. Not only removed items cannot be undone, bit also they cannot be deleted from the database. You should really load the desired items and use `context.mobj1s.Local.ToBindingList()` as data source. Then you'll be able to apply/undo changes because the context will track them for you. – Ivan Stoev Dec 05 '18 at 21:39
  • ok , I can set the datasource as you suggested , but when I execute , it's empty. How can I load ? or I should use my query with tolist ? – Adriano Dec 05 '18 at 22:26
  • Your query with `Load()` – Ivan Stoev Dec 06 '18 at 01:55

0 Answers0