c# - Delete many items with foreach and Entity Framework -
please see details :
database records
jn_country records :
jn_players records :
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
Post a Comment