错误1:The instance of entity type ‘name’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using ‘DbContextOptionsBuilder.EnableSensitiveDataLogging’ to see the conflicting key values.
错误2 insert_Identify 验证问题
可能原因为:同一个entity存在被多个context标记为add
1、获取了多个context对象,在netcore一般用同一个context,不要随意的去容器中取,如果没设置好,可能会导致多个context instance同时操作track EF
2、对顶层的entityEntry设置add状态,然后在导航属性又设置一遍
解决方案: 对症下药