2

I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign keys pointing to Author and Book tables to achieve many to many relation between Author and Book table.

When I generated models from database, the Author and Book models are created without any association among them. I was expecting "Books" under Author model and "Authors" under Book model. Am I missing anything here or this is the way it works? Here is my table Diagram enter image description here

And here is my model diagram

enter image description here

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Bishnu Paudel
  • 2,083
  • 1
  • 21
  • 39

2 Answers2

3

The table BookAuthor was not included by Entity Framework because it did not have a primary key. I fixed this issue by defining a primary key (on authorid and bookid) on the table.

Bishnu Paudel
  • 2,083
  • 1
  • 21
  • 39
0

is the relation in ur database defined between Book BookAuthor and Author BookAuthor ? --> How do I create a foreign key in SQL Server?

Community
  • 1
  • 1
davee
  • 156
  • 1
  • 10
  • Please look at the diagram above. – Bishnu Paudel Jun 26 '12 at 12:35
  • yea, u wrote the EF is generated from Database and there was no associations between the 3 tables. the reason why this happened: no asscociations were defined @Database! if you deploy the project/solution once again u should be able to access "Book.Author" or "Author.Book" – davee Jun 26 '12 at 12:53