How to configure many to many relationship using entity framework fluent API

后端 未结 4 2075
悲哀的现实
悲哀的现实 2020-11-27 20:41

I\'m trying to set up a many to many relationship in EF code first but the default conventions is getting it wrong. The following classes describes the relationship:

<
4条回答
  •  悲哀的现实
    2020-11-27 21:36

    modelBuilder.Entity()
                .HasMany(a => a.Products)
                .WithMany()
                .Map(x =>
                {
                    x.MapLeftKey("Account_Id");
                    x.MapRightKey("Product_Id");
                    x.ToTable("AccountProducts");
                });
    

提交回复
热议问题