Search code examples
c#sql-server-2008castle-activerecord

How to decorate (Active Record attribute) my primary key so it would generate as IDENTITY in SQL Server 2008


enter image description here

I am using Active Record and decorate my classes with attributes.

I have a primary key and the attribute is:

[PrimaryKey(PrimaryKeyType.Native, Column = "ID")]

Then I auto generate the table for SQL Server 2008 based on the C# class.

The result is then:

CREATE TABLE [dbo].[MyTable](
    [ID] [int] NOT NULL,

....

But what I want is:

CREATE TABLE [dbo].[MyTable](
    [ID] [int] NOT NULL IDENTITY,

As you can see, the IDENTITY keyword is missing from my generated T-SQL.

What attribute should I use to be able to make my primary key IDENTITY?

Thanks!


Solution

  • I'm assuming that you are using The Castle Project Active Records. So, you need PrimaryKeyType.Identity attribute. Code:

    [PrimaryKey(PrimaryKeyType.Identity, Column = "ID")]