I have a column named InvoiceNo
, the value for this is generated by code which is based upon the latest invoice number stored in the database and then incremented by one. My problem is the scenario that 2 users at the same time creates an invoice and both sees the same latest invoice number. This would generate the same invoice number for them which is what I'm trying to avoid.
This could be easier if I can set the InvoiceNo
column to be unique, but I can't. The column is not unique; it can be edited to an already existing value in the future. It's just that upon creation, we cannot create duplicates.
How can I handle this? I am using SQL Server, EF6.