其他分享
首页 > 其他分享> > [转载]Many to Many Relationship with ABP and EF Core

[转载]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 });
            });

 

标签:Core,Relationship,BookId,Many,HasOne,many,CategoryId
来源: https://www.cnblogs.com/sui84/p/15710390.html