c# - Delete many items with foreach and Entity Framework -


please see details :

database records

jn_country records :

enter image description here

jn_players records :

enter image description here

this code :

list<int> ids=new list<int> {12, 14};             foreach (var item in ids)             {                 try                 {                     _service.delete(item);                 }                 catch (exception e)                 {                  }             } 

first time => item 12

error :

innerexception {"the delete statement conflicted reference constraint \"fk_dbo.jn_players_dbo.jn_country_jn_country_id\". conflict occurred in database \"juventusapk\", table \"dbo.jn_players\", column 'jn_country_id'.\r\nthe statement has been terminated."} system.exception {system.data.sqlclient.sqlexception}

this true.because registered player country

second time => item 14

error :

innerexception {"the delete statement conflicted reference constraint \"fk_dbo.jn_players_dbo.jn_country_jn_country_id\". conflict occurred in database \"juventusapk\", table \"dbo.jn_players\", column 'jn_country_id'.\r\nthe statement has been terminated."} system.exception {system.data.sqlclient.sqlexception}

this not true.no players registered country. why error occurs


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -