Example #1
0
 private void RemoveRecord()
 {
     if (_selectedRecord.IsNew())
     {
         //If you clear the bindingsource for child records where the parent entity is tracked by
         //the context, it will lose tracking for the child entities and cascade operations like
         //delete will fail
         BindingSourceSupplierRegion.Clear();
     }
     //Note that cascade delete must be set on the FK in the db in order for the related
     //entities to be deleted.  This is a db function, not an EF function. However in addition
     //the model must know about the delete, otherwise the relationships in the context will
     //get messed up.  So after adding the cascade rule to the FK, the model must be updated,
     //and in order to refresh a relationship the tables must be deleted and re-added
     //Otherwise, we could do a delete loop
     //If using DbContext instead of ObjectContext, we could do eg
     //_context.SupplierRegion.RemoveRange(_selectedRecord.SupplierRegion)
     BindingSource.RemoveCurrent();
 }