I Have this simple model:
public class Code{
public int Id { get; set; }
public string Name { get; set; }
}
in my domain. The Id
is the primary key. Generating a migration for the class, would result this code:
CreateTable(
"dbo.Codes",
c => new {
Id = c.Int(nullable: false, identity: true),
Name = c.String(),
})
.PrimaryKey(t => t.Id);
This will obviously generates this T-SQL script:
CREATE TABLE [dbo].[Codes] (
[Id] [int] IDENTITY NOT NULL,
[Name] [nvarchar](max),
CONSTRAINT [PK_dbo.Codes] PRIMARY KEY ([Id])
)
OK. The problem is that I want to customize the identity column's seed and increment values. To doing that, the generated script needs be this one (for 100000 as seed and 23 as increment value, for example):
CREATE TABLE [dbo].[Codes] (
[Id] [int] IDENTITY (100000, 23) NOT NULL,
[Name] [nvarchar](max),
CONSTRAINT [PK_dbo.Codes] PRIMARY KEY ([Id])
)
So, the question is, how can I modify the generated migration to accept (100000, 23)
? Is there any way at all?
UPDATE:
It seems I have to note some points (my English is too bad, so excuse me if some points are not cleared).
I'm aware of DBCC CHECKIDENT
command. It's not the answer. Because:
It's just about reseeding the identity column. Not customizing increment value.
It works, after table created. In my case, I'm trying to do the job while creating table.
For resetting the increment value, table needs to be re-created - as far as I know. I'm NOT trying to RE-SET increment, neither the seed. I'm trying to SET them.
The question is not about altering db, or using SQL commands, or something like. I'm curious if the migration can be modified to customize the generated SQL.