How to set Identity Seed value in code-first?

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

Leave a Comment