efcore icon indicating copy to clipboard operation
efcore copied to clipboard

No IDENTITY for primary key in SQL server

Open andreyshv opened this issue 11 years ago • 2 comments

I've created simple SQL Server db with entity:

class Item 
{
  public int Id { get; set; }
}

generated script:

CREATE TABLE [dbo].[Item] (
    [Id]  INT            NOT NULL,
    CONSTRAINT [PK_Item] PRIMARY KEY CLUSTERED ([Id] ASC)
);

Isn't there should be IDENTITY token?

EF 7.0.0-bata8-15162 build

andreyshv avatar Aug 27 '15 05:08 andreyshv

Hmm, it seems to be working on 7.0.0-beta8-15534 for me.

This entity type...

class Item
{
    public int Id { get; set; }
}

...results in this migration...

migrationBuilder.CreateTable(
    name: "Item",
    columns: table => new
    {
        Id = table.Column<int>(isNullable: false)
            .Annotation(
                "SqlServer:ValueGenerationStrategy",
                SqlServerIdentityStrategy.IdentityColumn),
    },
    constraints: table =>
    {
        table.PrimaryKey("PK_Item", x => x.Id);
    });

...which produces this SQL.

CREATE TABLE [Item] (
    [Id] int NOT NULL IDENTITY,
    CONSTRAINT [PK_Item] PRIMARY KEY ([Id])
);

Could you share your DbContext code?

bricelam avatar Aug 27 '15 20:08 bricelam

I can't reproduce the issue now. I'm sorry!

andreyshv avatar Aug 28 '15 11:08 andreyshv