title: How to avoid inserting duplicate values in DB when users insert at the same time
body: <p>I have a column named <code>InvoiceNo</code>, 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.</p>
  <p>This could be easier if I can set the <code>InvoiceNo</code> 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.</p>
  <p>How can I handle this? I am using SQL Server, EF6.</p>