I have two entity that they have a many-to-many association. In use Model First. In sql Database, a separate table is created for many-to-many association composed by two table primary key. I want to add some fields to this table in EF. How can I do this?
Create a new table that has the fields you want to add plus a PK for the new table and a foreign key to each of the other tables. This will create a one-to-many relationship between each of the existing tables and the new one, which is effectively the same
as a many-to-many between the existing ones. For an example of that see the Enrollment table in this tutorial:
irani
Participant
898 Points
289 Posts
association and field
Feb 18, 2012 12:05 PM|LINK
I have two entity that they have a many-to-many association. In use Model First. In sql Database, a separate table is created for many-to-many association composed by two table primary key. I want to add some fields to this table in EF. How can I do this?
tdykstra
Contributor
4446 Points
622 Posts
Microsoft
Moderator
Re: association and field
Feb 18, 2012 05:07 PM|LINK
Create a new table that has the fields you want to add plus a PK for the new table and a foreign key to each of the other tables. This will create a one-to-many relationship between each of the existing tables and the new one, which is effectively the same as a many-to-many between the existing ones. For an example of that see the Enrollment table in this tutorial:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-a-more-complex-data-model-for-an-asp-net-mvc-application