Reputation: 835
i have a database and there is Movie Table and Country table and also i made a Movie_Country table for many to many relationship
but when i select my database and generate an entity model in my .net project this relationship returns to one to many for Movie and Movie_Country and also Country and Movie_Country
so i cannot add record to many to many table with code what can i do for generate model with many to many relationship as my database diagram show
Upvotes: 0
Views: 465
Reputation: 4672
In Entity framework many to many relationships need to be made with a table with both of the joining foreign keys as a compound primary key and no other properties on the table.
In other words make movieID and countryID your compound primary key and remove movie_country_id from T_Movie_Country and it should work. I also think that the foreign keys will have to be primary keys in their respective tables. So movieID would have to be your primary key in your T_Movie table.
Upvotes: 2