添加迁移时显示错误:
Both relationships between 'WorkCenter.Factory' and 'Factory' and between 'WorkCenter' and 'Factory.WorkCenters' could use {'FactoryId'} as the foreign key. To resolve this, configure the foreign key properties explicitly in 'OnModelCreating' on at least one of the relationships.
解决方案:
namespace APS.Infrastructure.Data.Config.BasicData; public class FactoryConfig : IEntityTypeConfiguration<Factory> { public void Configure(EntityTypeBuilder<Factory> builder) { builder.HasOne(m => m.Organization).WithMany().OnDelete(DeleteBehavior.NoAction); builder.HasIndex(m => m.Code).IsUnique(); builder.HasMany(m => m.WorkCenters).WithOne(m => m.Factory).HasForeignKey(m => m.FactoryId) .HasPrincipalKey(m => m.Id); } }
标签:relationships,FactoryId,解决方案,builder,Factory,EFCore,迁移 From: https://www.cnblogs.com/friend/p/18174710