Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book
- {
- public int BookId { get; set; }
- public string Title { get; set; }
- public Author Author { get; set; }
- public ICollection<BookCategory> BookCategories { get; set; }
- }
- public class Category
- {
- public int CategoryId { get; set; }
- public string CategoryName { get; set; }
- public ICollection<BookCategory> BookCategories { get; set; }
- }
- public class BookCategory
- {
- public int BookId { get; set; }
- public Book Book { get; set; }
- public int CategoryId { get; set; }
- public Category Category { get; set; }
- // NOT IN ALL THE EXAMPLES: public int ID {get; set;}
- }
- modelBuilder.Entity<BookCategory>()
- .HasKey(bc => new { bc.BookId, bc.CategoryId });
- modelBuilder.Entity<BookCategory>()
- .HasOne(bc => bc.Book)
- .WithMany(b => b.BookCategories)
- .HasForeignKey(bc => bc.BookId);
- modelBuilder.Entity<BookCategory>()
- .HasOne(bc => bc.Category)
- .WithMany(c => c.BookCategories)
- .HasForeignKey(bc => bc.CategoryId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement