EntityFramework Property Binding
I have class Pokemon:
Where PokeType is:
and I am getting a list of Pokemon from an external API, converting them to my own classes, and storing them in a Sqlite db where my DbContext is as follows:
When I am accessing the cached data, my Pokemon aren't filling in their Types and I don't know how to map the properties. EF has also made Pokemon and PokeType into two separate tables, which doesn't necessarily seem like a major issue, I just don't know how to workaround it. Some StackOverflow answers I've seen that may help have a .Map method that I don't seem to have - maybe I'm missing a dependency?
3 Replies
I have a DbContextFactory that I am using to get a new DbContext and assigning the calling class's ObservableCollection<Pokemon> prop to DbContext.Set<Pokemon>(), so it could also be how I'm calling and getting the values, but I think it's more to do with how I'm setting up the model creation.
You need to
.Include()
the properties you want to load
Or better yet, .Select()
that data into DTOs
I'd also store the types in its own table and map them with many-to-many, but that's besides the pointIs that on the DbContext or in the OnModelCreating?
On the DbContext!
Thanks, Z :)