We are using Code First with EF-core and I would like to add a column which has an Identity Seed starting at another value other to 1.
Currently we can set it to auto increment via the EntityTypeBuilder
during migrations using:
entityBuilder.Property(e => e.PropertyName).ValueGeneratedOnAdd();
However I cannot find out how to change the identity seed. Does it still need to be updated like it was with other versions of EF? e.g. writing some custom sql and running this during migration?
How to seed identity seed value in entity framework code first for several tables
How do I set Identity seed on an ID column using Entity Framework 4 code first with SQL Compact 4?
In EF-core there does not seem to be code for SqlServerMigrationSqlGenerator > override Generate(AlterTableOperation alterTableOperation)
?
Update 2020.
After EF Core 3.0 now you have a UseIdentityColumn extension method which can be used for setting the seed and increment values for identity columns.
builder.Property(prop => prop.Id)
.UseIdentityColumn(10000000, 1);
As per offcial documentation:
UseIdentityColumn Configures the key property to use the SQL Server IDENTITY feature to generate values for new entities, when targeting SQL Server. This method sets the property to be OnAdd.
Link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With