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

 

posted on 2021-12-20 12:37  白马酒凉  阅读(37)  评论(0编辑  收藏  举报

导航