I have two models with many-to-many relationship:
public class Person { public int PersonId { get; set; } public string Name { get; set;} public virtual ICollection<Hobby> Hobbies { get; set; } = new List<Hobby>(); }
and
public class Hobby { public int HobbyId { get; set; } public string Name { get; set; } public virtual ICollection<Person> Persons { get; set; } = new List<Person>(); }
In other words a person may have several hobbies and a hobby could interest many persons.
Now I have below model which has many-to-many relationship with the Person model:
public class Activity { public int ActivityId { get; set; } public string Name { get; set; } public virtual ICollection<Person> Persons { get; set; } = new List<Person>(); }
I have setup my Blazor WASM project and I have populated all the tables using EntityFramework Code First. Here is how my data structure in the database looks like:
Where am I stuck and what am I trying to achieve? I want to create a new activity with persons based on hobbies. Let's say that my Hobbies table contains the following hobbies:
And my Persons table contains the following persons:
I would like to create new activities like below:
The problem is that with my current design of the database, I can't keep track of what specific Hobby was chosen from each Person to create the Activity. I need a way to reflect that in the database.
For instance, if I browse my activity View.razor, the Hobby field in the activity would list all the hobbies and not that specific one I created the activity based upon.
Please feel free to ask for more details as I may have not been sufficiently clear about everything.
Any suggestions?