.Net Core auto-generated string primary key

.net-core asp.net-identity autogeneratecolumn entity-framework-core primary-key

Question

.Net Core 2.2 Identity framework has string primary key which is an auto-generated GUID. My question is how to have an auto-generated STRING primary key using Entity Framework 2.2?

1
2
5/17/2019 2:09:45 PM

Accepted Answer

You need to have the attribute [DatabaseGenerated(DatabaseGeneratedOption.Identity)] added to the column. See the official documentation for more details.

3
5/20/2019 3:45:37 AM

Popular Answer

Auto-generated primary key by using Fluent API

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Node>().Property(x => x.ID).HasDefaultValueSql("NEWID()");
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow