Consider an entity like this:
public class Document
{
public int Id { get; set; }
public long code { get; set; }
// Rest of Props
}
What I need is to generate a unique long code, and I prefer to generate it based on Id.
One simple classic but unsafe solution is to get the last Id and increase it by one and use, but I'm looking for a better solution, such as computed column, or any other way to assign code generation to database.
- I cannot access to Id if I try define it as a compute column.
- Marking it as Identity is not possible, because Id is already an Identity column.
- Creating a method to Get the last Id is not safe and clean.
By now I'm trying to do former classic solution with the help of transactions to make it safe.
Any better suggestion?