更新时间:2022-12-31 15:10:40
你不能拥有多对多(这是你创建
- 你所描述的)。
You cannot have that with the many-to-many (it's what you're creating - and what you described).
当您删除公司/联系人时,连接表记录将被删除。
When you delete company / contact - the 'join' table records get deleted.
您可以简化此操作,只需在配置中执行此操作(删除所有内容):
You can simplify that and just do this in your config (remove all you have):
modelBuilder.Entity<Company>()
.HasMany(c => c.Address)
.WithOptional()
.WillCascadeOnDelete(true);
modelBuilder.Entity<Contact>()
.HasMany(c => c.Address)
.WithOptional()
.WillCascadeOnDelete(true);