Is this a good practice to insert into a many-to-many table?
user = new User
{
Id = userId,
UserName = username,
FirstName = firstName,
LastName = lastName,
UsersBooks = new List<UsersBooks>()
};
book = new Book
{
Title = "randomTitle2",
Genre = "randomGenre2",
UsersBooks = new List<UsersBooks>()
};
usersBooks = new UsersBooks
{
User = user,
Book = book
};
And at last I add it to the context
actContext.UsersBooks.AddAsync(usersBooks);
So I have this UsersBooks collection in each of the classes - user & book. One user can have many books and one book can be acquired by many users(copies of Harry Poter, let's say). So should I every time create a new
- usersBook and add it while passing the user and the book each time? Because I see that after that the book is added to it's according table, which is correct. Maybe I am asking if there is a better way in terms of most used by experienced developers
UsersBooksclass. Check this