I have a MVC 5 application that access a Sql Database through Entity framework. I have a invoice model that looks like :
class Invoice
{
public int Id {get; set;}
public int InvoiceNumber {get; set;}
// other fields ....
}
InvoiceNumber have a lot of legal constraint. It needs to be unique, and incremental with no gap. I initially though that my Id would do the job till I have found that for some reasons I may have gaps between the id ( 1,2,3,...,7 then 1000 ... , for inst see Windows Azure SQL Database - Identity Auto increment column skips values ). Take into account that many clients could be connected at the same time so these Inserts may be concurrent.
Does someone know how to force EF or the database to generate this kind of invoice number.