Answer the question
In order to leave comments, you need to log in
What is the best way to organize the database structure?
There is a user, there is a book.
Each user has a set of books, respectively, different users can have the same book (there is more than one instance).
Advise how best to organize the structure, the user will constantly add books either from the database or write his own there (which others can then write to themselves), and it will be necessary to look at which he has and which he does not.
So far, I have everything in a many-to-many connection, there is a user table, there is a book table, and an intermediate one is being built, with user-book matches, but some problems arise, and I think because of this, it would be necessary to normalize.
I use code first EF.
UPDATE:
This is how I select books for the list that the user does not have, respectively, a newly registered user should have all the books from the database there, but if you do not create a user in advance when initializing the database, then the list will be empty, although Books are written to the database.
var books = db.Books.Where(x => x.Users.Any(y => y.Id != user.Id));
SelectList newbooks = new SelectList(books, "Id", "Name");
Answer the question
In order to leave comments, you need to log in
Well, what do you want to do here? normal solution. There is nothing to optimize here. What problems arise?
var books = db.Books.Where(x => !x.Users.Contains(user));
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question