我通过添加存储两个Foo
的主键的关系实体Bar
在实体FooBarRelationship
和Foo
之间实现了多对多关系和Bar
作为外键。为了避免在FooBarRelationship
上重复记录,我定义了一个包含两个外键的复合键。现在,每当我尝试使用它们之间的重复关系更新Foo
时,Entity Framework Core都会引发以下异常:
System.Exception: The instance of entity type 'FooBarRelationship' cannot be tracked because another instance with the same key value for {'FooId', 'BarId'} 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.
Entity Framework Core是否提供任何方法来配置实体以接受INSERT OR IGNORE
或INSERT ON DUPLICATE KEY
类型的行为?