6
Good morning,
I’m studying the Entity Framework Code First and I’m wondering how I should create an Nxn model with extra information in the relationship table. For example:
Let’s assume the following relationship (image taken from the MSDN website)
So far so good, I create the model Person and Course and establish the relationship between them with Icollection and "saying" that a Course has several Person and vice versa and the EF creates this relationship (Courseinstructo).
Now let’s assume that you need some extra information in the Courseinstructo table, for example Active or Datainicio. In the proposed form the EF creates the table automatically not allowing me to add extra field in the relationship, right?
How should I proceed with this case? You should create 3 models:
- Person
- Course
- Courseinstructo
and establish Person and Course’s relationship with Courseinstructo? What would be the outline of this code and then the manipulation of these records (INSERT, UPDATE, DELETE)? Thank you.
I did all this. I created the classes and relations as indicated. Each one with its Dbset in Context and its repository. It works by adding Person and Course but adding their error ratio. Courseinstructor.Person = Person(previously registered) and the same for Course and then save.
– Renato
Hi @Renato, if this helped you find the solution to the problem. Remember to mark the post as a solution, to help other users with a similar issue in the future :)
– Felipe Oriani
I was able to identify the problem. Thank you. I would like to refer to a Lonk that also contributed. http://answall.com/questions/14829/relacionamento-muitos-para-muitos-entity-framework-6
– Renato