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

Pregunta

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!

¿Fue útil?

Solución

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

[PrimaryKey(PrimaryKeyType.Identity, Column = "ID")]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top