views:

145

answers:

1

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 ShopBindingNavigatorand 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.

A: 

Cannot insert the value NULL into column 'Location', table 'MyDB.dbo.Shops'; column does not allow nulls means you table does not accept NULL.

so can you check in the table if the column is nullable or not. If it is not nullable then when you say it has succeeded in your first scenario have a look at you DB. Somehow you must be inputting some default values into the tables.

Ashwani Roy
im not sure if you understood the post above... im talking about a scenario of Adding a line and Deleting a line,and only after the deletion of the line im Commiting the changes with SaveChanges(). in the first scenario i did it to the futher.in the second i did it for the child. the child failed, allthough the futher has same null restrictions.
_Avishay_