❔ EntityFramework Relations doesn't work
Hewoo, I'm new to EntityFramework and I'm trying to make a simple One to Many relation but it doesn't work
13 Replies
This is how to models looks like
When I try to load the data the Numbers field in contact is null, but the data exists in the database
the error
that's the ContactContext class
what am I missing here to make the relation work?
when querying for an entity, the relationships are not loaded unless you include them.
https://learn.microsoft.com/en-us/ef/core/querying/related-data/eager
Eager Loading of Related Data - EF Core
Eager loading of related data with Entity Framework Core
Ooo 👀 I will read it
for some reason its searching for a table called PhoneNumbers but the correct name would be PhoneNumber (without the S)
do I need to rename the model class?
You forgot to declare a
DbSet
for PhoneNumbers
Oooo
It is a standard EF convention to pluralize table names while keeping your entity names in singular form.
after adding this line to the Context everything is working as intended! thanks
Ooo 👀
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.