首页 新闻 会员 周边 捐助

EF Core多对多中间表已配置主键为何在迁移时候还提示需要主键?

0
悬赏园豆:30 [已关闭问题] 关闭于 2018-10-25 10:47
    public class TagProgramMap : EntityTypeConfiguration<TagProgram> {
        public override void Map(EntityTypeBuilder<TagProgram> builder) {
            builder.HasKey(t => new { t.ProgramId, t.TagId });
            builder.HasOne(t => t.Tag).WithMany(t => t.TagPrograms).HasForeignKey(t => t.TagId)
                .OnDelete(DeleteBehavior.Restrict);
            builder.HasOne(t => t.Program).WithMany(t => t.TagPrograms).HasForeignKey(t => t.ProgramId)
                .OnDelete(DeleteBehavior.Restrict);
        }
    }

错误消息:InvalidOperationException: The entity type 'TagProgram' requires a primary key to be defined.

ef core版本是2.1

远扬的主页 远扬 | 初学一级 | 园豆:30
提问于:2018-10-25 10:46
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册