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

我通过添加存储两个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类型的行为?

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

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3159152.html

大家都在问