[转载]Many to Many Relationship with ABP and EF Core

https://community.abp.io/articles/many-to-many-relationship-with-abp-and-ef-core-g7rm2qut

https://github.com/EngincanV/ABP-Many-to-Many-Relationship-Demo

 

builder.Entity<BookCategory>(b =>
            {
                b.ToTable(BookStoreConsts.DbTablePrefix + "BookCategories" + BookStoreConsts.DbSchema);
                b.ConfigureByConvention();

                //define composite key
                b.HasKey(x => new { x.BookId, x.CategoryId });

                //many-to-many configuration
                b.HasOne<Book>().WithMany(x => x.Categories).HasForeignKey(x => x.BookId).IsRequired();
                b.HasOne<Category>().WithMany().HasForeignKey(x => x.CategoryId).IsRequired();

                b.HasIndex(x => new { x.BookId, x.CategoryId });
            });

 

上一篇:多对多(many-to-many)


下一篇:TZOJ3465: How many seats(数位DP)