Base solution for your next web application
Open Closed

Are Sequences supported for Primary Keys #4270


User avatar
0
Kelly created

I am using the Asp.Net Core & Angular template, and want to convert to an existing SQL Server 2017 database. The Database uses Sequences to generate the primary key. I noticed that if I change the AuditLogs table to use a Sequence Id (NEXT VALUE FOR [Sequences].[AuditLogId]), I get a database concurrency exception. Are Sequences supported?


1 Answer(s)
  • User Avatar
    0
    Kelly created

    I was able to resolve this by adding the following to OnModelCreating();

            modelBuilder.Entity<AuditLog>()
                .ToTable("AuditLogs", "Application")
                .Property(x => x.Id)
                .HasDefaultValueSql("NEXT VALUE FOR [Sequences].[AuditLogId]");
    

    If anyone knows a better way to handle this, please comment. I have over 100 tables in this database, so this will get a little tedious.