Scaffolding Error - Requires a primary key to be defined
Here's the class it's referring to
I'll be honest I've read the key info in the error link and don't exactly understand what all of this means. I don't quite understand how keys work either.
35 Replies
Maybe you need one of those:
1. Property name ID
2. Add attribute called [Key] to one of your current property
3. Define your Key on ModelCreating
4. Tell EF that your entity doesn't have key using .HasNoKey()
Yeah I get that much, I guess I should ask what a key does.
I don't really understand this despite trying to read on the docs
so I have a
Card { ImageUris ImageUris { get; set; }
and then ImageUris { ... }
A key is the column/property of your row/object by which that object or row will be identified
okie doke
You can work without tho
as says the description you posted
yeah I'm just not understanding tbh
You know SQL right?
I mean I vaguely understand, but in practice of what I'm trying to do
vaguely, I've done a few tutorials
Okay,
Can I just ask a couple dumb questions particular to what I'm doing? Or questions I imagine will help me understand? lol
sure sure, ask away
What Could I use as a primary key for the imagesUris?
@@
public int Id {get; set;} 🙂
the json doesn't serve an ID
for the images
u mean you don't want user to see your ID in Json?
again, I'm sorry lol. I am a brick.
no no he dont wna see id
he dno what to do with id
No no, I just wholly don't understand this concept
where do you get the json?
from an api, I'm trying to make a magic the card game deck building app
figure that'd be a fun practical way to learn working SQL
cool
it is
but if you dont get the [Key] concept, i wouldnt continue on until i do
So next question I guess. I can take any property in the
ImageUris
make it the PK, and the Card
object will know to associate that specific set of ImageUris
with it?
I get the idea, I just don't get how to use it
I just have to slap a PK on a property, and it'll keep track of which card references which images?no not just any property
lol okay
in sql database, records are indexed. An integer is the best to do this
You should add public int to your urls model
the image urls will be unique so I figured that'd be good lol
and make the Id column in sql to PRIMARY AUTO INCREMENT
Well it can work without PK
like you say, the urls are unique
you just have to configure the entity in the OnModelCreating..
I'm all ears bud. I'll google PRIMARY AUTO INCREMENT too when we're done
Yeah I haven't done annnything like that
only automated stuff
and some sql functions
in pgadmin / SSMS
I did see some stuff like that in docs so I'll take a second look.
I really didn't think it'd be this difficult lol. Every step of this programming journey has felt like climbing a mountain to find another mountain xD
Thts the job lol
But why dont you take a udemy course ?
Well I've done a few MVC tutorials, one was an entire course
So I was hoping I'd be able to get it off the ground, but turns out nope
Sure you will
Should I take an EFCore specific class
I can screenshare and setup an example real quick if u want
sure that'd be really cool.