This shows how to set the identity seed.
EF Code First - how to set identity seed?
dataannotations set identity seed value on Primary Key with code first
How do you set the identity increment value using code first?
This shows how to set the identity seed.
EF Code First - how to set identity seed?
dataannotations set identity seed value on Primary Key with code first
How do you set the identity increment value using code first?
There is no way to do it.
None of the ways to configure the entities (conventions, attributes, fluent API) allow to do that. You can neither implement it using custom conventions (in short, a custom convention checks the name, attributes, type, containig type or whatever of a column, and then uses fluent API to config the column, or entity). At least up to EF 6.1.1.
The only way to manipulate an identity in SQL Server is by using DBCC CHECKIDENT
, but this only allows to change the seed value, and not the increment.
If you want to change the increment you have to drop the column and create it again in the database initializer Seed
method. The problem is that you have to drop and create all the keys (PK or FK) related to this column. (This applies up to SQL Server 2014)
You can have a look at this answer where I explain the possible solutions, alternatives and work arounds, which work, and which don't, and a link to vote to get this included in a future release of EF.