C
C#•3y ago
BigggMoustache

Scaffolding Error - Requires a primary key to be defined

Here's the class it's referring to
public class ImageUris
{
[JsonPropertyName("small")]
public string Small { get; set; }

[JsonPropertyName("normal")]
public string Normal { get; set; }

[JsonPropertyName("large")]
public string Large { get; set; }

[JsonPropertyName("png")]
public string Png { get; set; }

[JsonPropertyName("art_crop")]
public string ArtCrop { get; set; }

[JsonPropertyName("border_crop")]
public string BorderCrop { get; set; }
}
public class ImageUris
{
[JsonPropertyName("small")]
public string Small { get; set; }

[JsonPropertyName("normal")]
public string Normal { get; set; }

[JsonPropertyName("large")]
public string Large { get; set; }

[JsonPropertyName("png")]
public string Png { get; set; }

[JsonPropertyName("art_crop")]
public string ArtCrop { get; set; }

[JsonPropertyName("border_crop")]
public string BorderCrop { get; set; }
}
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
FroH.LVT
FroH.LVT•3y ago
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()
BigggMoustache
BigggMoustacheOP•3y ago
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 { ... }
mikepattyn
mikepattyn•3y ago
A key is the column/property of your row/object by which that object or row will be identified
BigggMoustache
BigggMoustacheOP•3y ago
okie doke
mikepattyn
mikepattyn•3y ago
You can work without tho as says the description you posted
BigggMoustache
BigggMoustacheOP•3y ago
yeah I'm just not understanding tbh
mikepattyn
mikepattyn•3y ago
You know SQL right?
BigggMoustache
BigggMoustacheOP•3y ago
I mean I vaguely understand, but in practice of what I'm trying to do vaguely, I've done a few tutorials
mikepattyn
mikepattyn•3y ago
Okay,
BigggMoustache
BigggMoustacheOP•3y ago
Can I just ask a couple dumb questions particular to what I'm doing? Or questions I imagine will help me understand? lol
mikepattyn
mikepattyn•3y ago
sure sure, ask away
BigggMoustache
BigggMoustacheOP•3y ago
What Could I use as a primary key for the imagesUris?
FroH.LVT
FroH.LVT•3y ago
@@
mikepattyn
mikepattyn•3y ago
public int Id {get; set;} 🙂
BigggMoustache
BigggMoustacheOP•3y ago
the json doesn't serve an ID for the images
FroH.LVT
FroH.LVT•3y ago
u mean you don't want user to see your ID in Json?
BigggMoustache
BigggMoustacheOP•3y ago
again, I'm sorry lol. I am a brick.
mikepattyn
mikepattyn•3y ago
no no he dont wna see id he dno what to do with id
BigggMoustache
BigggMoustacheOP•3y ago
No no, I just wholly don't understand this concept
mikepattyn
mikepattyn•3y ago
where do you get the json?
BigggMoustache
BigggMoustacheOP•3y ago
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
mikepattyn
mikepattyn•3y ago
cool it is but if you dont get the [Key] concept, i wouldnt continue on until i do
BigggMoustache
BigggMoustacheOP•3y ago
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?
mikepattyn
mikepattyn•3y ago
no not just any property
BigggMoustache
BigggMoustacheOP•3y ago
lol okay
mikepattyn
mikepattyn•3y ago
in sql database, records are indexed. An integer is the best to do this You should add public int to your urls model
BigggMoustache
BigggMoustacheOP•3y ago
the image urls will be unique so I figured that'd be good lol
mikepattyn
mikepattyn•3y ago
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..
BigggMoustache
BigggMoustacheOP•3y ago
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
mikepattyn
mikepattyn•3y ago
Thts the job lol But why dont you take a udemy course ?
BigggMoustache
BigggMoustacheOP•3y ago
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
mikepattyn
mikepattyn•3y ago
Sure you will
BigggMoustache
BigggMoustacheOP•3y ago
Should I take an EFCore specific class
mikepattyn
mikepattyn•3y ago
I can screenshare and setup an example real quick if u want
BigggMoustache
BigggMoustacheOP•3y ago
sure that'd be really cool.
Want results from more Discord servers?
Add your server