Seeding Data Into Database
Hello there,
I'm still new to asp.net and i've been learning through a course on this Course.
At episode 83. they were talking about seeding data into database but when i tried to apply the code they used i had an error about the required fields being null
the data are random generated in a .json file.
5 Replies
User:
Exception
Json data file
Seed Class
the error is happining because of the PasswordHash and PasswordSalt are not modified in the json folder
but you can see that i have given them a value in the seed class
and they already have a default value of an empty array in the User.cs class
have you empirically tried to have those field in the json like
or even
"PasswordHash": null
i think it works
i don't know how required
behave with stj but maybe it's more strict than thatthe issue is in the User class you have marked PasswordHash and PasswordSalt as required, which means during deserialization it will expect a value to be present in the json, it doesnt matter if you set the values later on inside a for loop, the error states during deserialization its unable to find PasswordHash and PasswordSalt values .
try removing required from User class and handling the required logic through code, else add empty string in json like
"PasswordHash":"",
"PasswordSalt":""