Answer the question
In order to leave comments, you need to log in
Entity Framework Database First relationship n:m?
Good evening.
I have a database in which there are the following tables
Players
Games
PlayersAndGames (only 2 fields IdGame and IdPlayer)
i.e. implementation of the n:m relationship between the Players Games entities
When creating an .edmx model from the database, I "lose" the PlayersAndGames table and get 2 navigation properties in the Player and Game model classes (respectively, Playes in the Game class and Games in the Players class).
Judging by what I found on this subject, this is how it should be if the intermediate table has only 2 fields.
I am using client application on asp.net mvc to work with db. Data output is carried out without problems. But when I try to change the data, I get an error: "...DefiningQuery and no element exists in the element...". As far as I understand, this error is due to the lack of a primary key in the PlayersAndGames table. But adding it to the database, I get a completely different .edmx data model, where instead of 2 tables I have 3. And as far as I understand, this is not very good in my case.
The question is how to proceed in this case?
Answer the question
In order to leave comments, you need to log in
Look at the Fluent API, you can describe one-to-many relationships there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question