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
The database is up to date using add-migration, update-database.
show the code for the
repo.Create
methodand save just calls savechanges, I guess
Yes
await _context.SaveChangesAsync();
but the save method is not awaited
if you call async code in that, you're fetching the ID before the save goes through
I will add await before the Save and see if it fixes
Yessssss, it works. thank you!
Always be careful about mixing sync/async 🙂
any command here to post it as solved?
or just delete the post?
/close
✅ This post has been marked as answered!