如何在插入时多对多关系中忽略重复关系?

时间:2019-11-05 13:44:30

标签: entity-framework-core entity-framework-core-2.2

我通过添加存储两个Foo的主键的关系实体Bar在实体FooBarRelationshipFoo之间实现了多对多关系和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 IGNOREINSERT ON DUPLICATE KEY类型的行为?

0 个答案:

没有答案
相关问题