EF6: How to generate a unique number automatically based on entity Id
问题 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.