Primary key from object instead of a native
I'm making a school asignement and we have to use a personally made class called EmployeeNumber as a primary key.
I've tagged the field with [key] in the concerning class, but I keep getting the error that the EF can't find a primary key.
The following class (employeenumber) https://hatebin.com/temmimpnee
is a 'convertible' class, or should be, given the implicit operators.
To my knowledge this should constitute to EF that the class should be saved in the SQL Table as a String but it doesn't seem to recognize it?
Given the EmployeeConfiguration to equally define a key
https://hatebin.com/gfhbwbzahf
and the Employee class
https://hatebin.com/ilhlrjtuee
can anyone help me figure out why it doesnt take the primary key ?
most of this code is given by the assignment, so most questions about 'why did you do it this way' is probably answered with :'because the code was given to us this way : s '
I apologize in advance.
6 Replies
if you have already a Configure method then why is there a [Key] attribute on Id
and also a
[Column("Id")]
...and also a [Required]'
while it's a nullable?!because the configure didnt do anything, I added the key annotation on top of it
and then i added column id in the hopes that it would help/change. it used to be named number too, then i renamed it 'Id' and i added requiered hoping that it would be detected
it shouldnt be nullable btw i believe a key shouldnt be nullable at all ?
foreign key could be nullable
primary can't
i believe it has to be called somewhere in your code
let me look up where i call it
it should be in the DbContext
this is in program.cs and i was told, or rather I currently believe(d) that the entityconfiguration was called here
my dbcontext is as good as empty
let me put my onmodelcreating method in there ...
here's the next error haha that worked
seems like i forgot all about the onmodelcreating ... looked for 2 horus yeterday night before giving up for rubber ducking for me dont, i appreciate it