❔ EF Core tries to query a non-existant column for no apparent reason
I am making a simple web API in ASP.NET with MVC. I have the following model Event:
and the following EventController:
and the following DbContext:
I've commented out some of the models which are not in use right now.
I am trying to get all events, but when I try to do that, it gives me the following error:
with a bunch of further lines (I can show if needed). The error seems clear to me, the column "GameId" doesn't exist, but I don't understand why it would even try to get it in the first place?
12 Replies
help him.
If you comment out the Game model/context, does it work? What does the Game model look like?
[Column("challonge_id")]
hurts me on a physical level in more ways than one
Seems something was misconfigured at some point
Maybe GameId
prop doesn't have the column name specified
And the database has some game_id
columnThis is the Game model:
could you explain what's bad about this? this is just a column in the database relating each event to a bracket made in challonge.com
Ah, well, for the relationship between the game and the event to exist, the event has to have game ID
^
You don't have that set up explicitly it seems, so EF tries to generate it
I just see specifying names as useless. Just let EF handle it and name everything however it sees fit
unless you're going to be writing queries outside of EF, hard agree.
ah like that
ill likely end up doing that with migrations yeah
is how I'd set it up
You have both the nav property and the ID if need be, and everything is convention-based so zero-config
alright i got something working
thank you guys :)
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.