DataBinding with entityframework error

I have an application that consists of a simple DB schema:

Networks 1 → * Shops

I use entityframework (the default EntityObject code generator) with winforms, I use a DataBinding for the grid for the CUD of these objects, 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 data bindings work well and are synchronized, I can use CUD on both grids in the form and easily switch to _context.SaveChanges().

  • First scenario

a simple scenario of pressing "+" (add) on NetworkBindingNavigatorand immediately after "X" (delete) on this empty line on the grid, and finally, I will move on to context.SaveChanges() without problems.

  • Second scenario

"+" () ShopBindingNavigator, "X" () , , , _context.SaveChanges(), :

System.Data.UpdateException: . . . --- > System.Data.SqlClient.SqlException: NULL "", "MyDB.dbo.Shops"; nulls

: ( NULL )?

.

+3
1

NULL "", "MyDB.dbo.Shops"; column nulls , NULL.

, NULL . , , , , . - .

-1

Source: https://habr.com/ru/post/1753048/


All Articles