0
我有以下模式:错误更新实体时,EF代码第一
如何正确使用EF代码第一种方法更新实体?当我试图做到这一点的:
this._context.Entry(foundEntity).CurrentValues.SetValues(entity);
this._context.Entry(foundEntity).State = EntityState.Modified;
它抛出异常,并说:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Bets_dbo.Matches_MatchID". The conflict occurred in database "UltraPlay.Betting.Platform", table "dbo.Matches", column 'ID'.
The statement has been terminated.
是否有可能通过根对象和所有孩子的更新?如何正确地做到这一点干净和快速?
你能展示你的实体吗? –
请分享你的代码,并告诉你在哪里得到错误 –
我想,变量“实体”是分离的。这样对吗? – jannagy02