C
C#•3y ago
HappyTeaKid

POST SQL Identity keeps returning id = 0 [Answered]

As you can see it keeps returning 0 value. It actually creates an object with different id in the database. How can I get the proper value?
14 Replies
HappyTeaKid
HappyTeaKidOP•3y ago
HappyTeaKid
HappyTeaKidOP•3y ago
The database is up to date using add-migration, update-database.
Pobiega
Pobiega•3y ago
show the code for the repo.Create method
HappyTeaKid
HappyTeaKidOP•3y ago
Pobiega
Pobiega•3y ago
and save just calls savechanges, I guess
HappyTeaKid
HappyTeaKidOP•3y ago
Yes await _context.SaveChangesAsync();
Pobiega
Pobiega•3y ago
but the save method is not awaited
Pobiega
Pobiega•3y ago
Pobiega
Pobiega•3y ago
if you call async code in that, you're fetching the ID before the save goes through
HappyTeaKid
HappyTeaKidOP•3y ago
I will add await before the Save and see if it fixes Yessssss, it works. thank you!
Pobiega
Pobiega•3y ago
Always be careful about mixing sync/async 🙂
HappyTeaKid
HappyTeaKidOP•3y ago
any command here to post it as solved? or just delete the post?
Pobiega
Pobiega•3y ago
/close
Accord
Accord•3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server