Hi,
I have an application which consists of simple schema of DB:
Networks 1-->* Shops
i use entityframework (Default EntityObject Code Generator) with winforms, i use DataBinding to a grid to CUD these entities, i have :
DbObjectModelContainer _context = new DbObjectModelContainer();
_context.ContextOptions.LazyLoadingEnabled = true;
NetworkBindingSource.DataSource = _context.Networks;
ShopsBindingSource.DataSource = NetworkBindingSource;
ShopsBindingSource.DataMember = "Shops";
NetworkBindingNavigator.BindingSource = NetworkBindingSource;
ShopBindingNavigator.BindingSource = ShopsBindingSource;
NetworkDataGridView.DataSource = NetworkBindingSource;
ShopDataGridView.DataSource = ShopsBindingSource;
all databinding is working good and synchronized, i can CUD on both grids on the Form and go to _context.SaveChanges()
with no problem.
- First Scenario
a simple scenario of Pressing "+"(add) on the NetworkBindingNavigator
and right afterwards "X"(delete) on this empty line on the grid and finally i go to context.SaveChanges()
succeed without a problem.
- Second Scenario
when i press "+"(add) on the ShopBindingNavigator
and then right afterwards i press "X"(delete) on this empty line on the grid and finally i go to _context.SaveChanges()
i get :
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Location', table 'MyDB.dbo.Shops'; column does not allow nulls
my question is why didnt it happen in the first scenario as well (i dont allow NULL in Networks table as well) ?
Thanks.