mardi 7 août 2012 20:10
I'm using EF4 in Windows Forms. My code is VB.Net. I use a BindingSource for all DataGridViews. I do not use the BindingNavigator.
I'm trying to determine something:
In a Winforms DataGridView bound to a BindingSource whose DataSource is an ObjectResult(Of T), if a row is deleted - should the underlying entity's state be set to EntityState.Deleted?
If so, couldn't I then call .SaveChanges on the context in the BindingSource.ListChanged event to delete that entity? (ListChangedType would of course be ListChangedType.ItemDeleted)
Toutes les réponses
mercredi 8 août 2012 19:14Modérateur
ListChanged actually finishes before the delete has flowed through to Entity Framework. So you can't call SaveChanges in that event and have the data binding work.
However, the UserDeletedRow event on the data grid should be late enough for you to call SaveChanges and have it work. Just be sure to check that it isn't fired in any situations that aren't right for your the behaviour you want.
We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.
mercredi 8 août 2012 21:19
Excellent information, many thanks.