❔ EntityFramework help determining relationship
System.InvalidOperationException: Unable to determine the relationship represented by navigation 'Event.Planner' of type 'User'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
User.cs
Event.cs
11 Replies
You need to properly handle the many-to-many relationship between users and events.
Also, don't mix your models. It looks like you have some data annotations for form validation in there, but this should only be for interacting with the database.
should i do this by creating a EventUser class?
Yep
what would be the difference by creating the new class and using something like this
you don't need an explicit join entity iirc
btw
is this a good design?
or should i only store the users on the event class
depends how you need to access them
my ideia initially was to make a user with a list of events that he created
but now im wondering whats easier/better to implement
i could just store the users inside the event class
and when i try to get all the events that an user participates/has created, i just iterate over their ids
keep in mind you aren't "storing" these in either, no matter what you do you will always have a join table between users and events in your database
the navigation properties just expose that relationship to you
whether you want it from both sides or just one is up to you and how you want to control how you can interact with the model
oh TIL
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.