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

StackOverflow https://stackoverflow.com/questions/11936756

Question

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!

Was it helpful?

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")]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top