原文:The instance of entity type 'XXX' cannot be tracked because another instance with the same key value for {'XX'} is already being tracked.

在做單元測試的時候碰到以下報錯: 具體報錯代碼如下: 項目平時運行是沒問題的,但在單元測試時會報錯,可能跟在測試時一個方法里多次調用有關。 我的做法如下:使用try catch,在異常里操作 修改狀態 Entry entity .State EntityState.Detached 再次調用本身 具體代碼如下: ...

2020-12-23 16:32 0 954 推薦指數:

查看詳情

 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM