开发者

How do you make a column an auto incremented primary key in the various .NET ORMs?

开发者 https://www.devze.com 2022-12-17 17:59 出处:网络
How do you make a column (let\'s call it OrderID) an auto incremented primary key in the various .NET ORMs?

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

Linq To SQL

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.


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;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号