0

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:

  1. It's just about reseeding the identity column. Not customizing increment value.

  2. It works, after table created. In my case, I'm trying to do the job while creating table.

  3. 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.

  4. 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.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
amiry jd
  • 27,021
  • 30
  • 116
  • 215
  • http://stackoverflow.com/questions/28920768/how-to-seed-identity-seed-value-in-entity-framework-code-first-for-several-table, http://stackoverflow.com/questions/23887992/how-to-set-initial-value-for-auto-incremented-property-databasegeneratedoption – CodeCaster Sep 23 '15 at 14:36
  • Thanks to links. I updated the question. – amiry jd Sep 23 '15 at 15:21
  • Yeah I understand that you want it in the initial migration that creates the database, but as far as I found there's no way to do that. – CodeCaster Sep 23 '15 at 15:25
  • @CodeCaster Ooops it's too bad ): Thanks to the help – amiry jd Sep 23 '15 at 15:27

0 Answers0