It depends on the logic in the GetNextPrimaryKey method.
If your method is executed in several threads, then you will have a chance that the same key will be assigned to several objects.
But if your GetNextPrimaryKey promotes your key and always returns a new key, whether it is used or not, then there is no problem.
But if your logic is simply to find out the last key used and make the key + 1, then in multi-threaded situations or in web applications there will be conflicts.
It would be best to use some kind of stored procedure and always return a new key from SP, so there would be no problem if GetNextPrimaryKey is executed in parallel.
source share