views:

45

answers:

1

How do you make a column (let's call it OrderID) an auto incremented primary key in the various .NET ORMs?

Linq To SQL

  • [Column(Name="OrderID", IsPrimaryKey=true, IsDbGenerated=true)]

Entity Framework

  • [EdmScalarProperty(EntityKeyProperty=true, IsNullable=false)] (Not possible to specify autoinc?)

NHibernate

  • [Id(Name = "OrderId"), Generator(1, Class ="Identity")]

I have started this question in order to have a one-stop answer to this question and to solicit more information from the .NET community. If you use an ORM not listed here, please edit this question and post the appropriate attributes.

+1  A: 

In Habanero (http://www.habanerolabs.com/) you can either set it up via the ClassDef.Xml as follows:

property name="AutoIncrementingProp" type="Int32" autoIncrementing="true"

or you can set it up in Firestarter by ticking Autogenerate (This will generate the ClassDefs with autoIncrementing.

Or if you are using more fluent syntax i.e. you are not setting up you Business Objects via ClassDefs then you would do.

BOProp autoIncrementingProp = new BOProp(.......,true,.);

or autoIncrementingProp.AutoIncrementing = true;