开发者

DataBinding with entityframework bug

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 开发者_StackOverflowis 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜