Hi,
how do I establish many-to-many relationship? For example, if a blog has many entries and and entry can belong to many blogs?
I tried setting doing it code first as suggested in this url <a class="postlink" href="http://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx">http://www.entityframeworktutorial.net/ ... first.aspx</a> but when I do Add-Migration, the script do not seems to create the joining table.
4 Answer(s)
-
0
Can you share your Blog and Entry entities ?
-
0
Entity framework does not create the table because primary keys in both entities have same name "Id". For entity framework to generate correct relationship, primary key names should be different. Your only solution is to use Fluent API.
-
0
I see, I will use fluent api then. Thanks alot guys.
-
0
By the way, I do have another problem with many-to-many relationship - after adding navigational property, I get an error
The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.
But this can be due to my heavily spoiled testing project and I intend to check it on a fresh project when I will test last version.