I have the repository method inside my asp.net mvc web application, to automatically generate a unique sequence number called Tag:-
public void InsertOrUpdat
A complete solution to this problem would be to combine the use of an auto incrementing column and computed column.
The table would look something like this:
CREATE TABLE [dbo].[somedata](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[reference] [varchar](50) NULL,
[STag] AS ('S'+CONVERT([varchar](19),[id],(0))),
CONSTRAINT [PK_somedata] PRIMARY KEY CLUSTERED ([id] ASC)
)
With a mapping:
public class SomeDataMap : EntityTypeConfiguration
{
public SomeDataMap()
{
// Primary Key
this.HasKey(t => t.id);
// Properties
this.Property(t => t.id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(t => t.reference)
.HasMaxLength(50);
this.Property(t => t.STag)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
}
}