C# – Non primary key Identity AutoIncrement Mapping using Fluent NHibernate

cfluent-nhibernatenetnhibernatesql server

I need to manage an additionnal Auto Increment column using Fluent NHibernate.

All my domain classes use Assigned Guid as ID but in a particular entity i need an additionnal auto increment value.

I've tried the following mapping, the column is well created in SQL Server but the Identity Specification isn't set.

        Id(x => x.OrderId).GeneratedBy.Assigned();

        Map(x => x.TicketNumber).ReadOnly().Generated.Always().Not.Nullable();

Any help ?

Best Answer

On the off-chance you are still after an answer for this question, you may be able to find some help in this SO post: fluent nhibernate auto increment non key (Id) property

In Hibernate:

<property name="Foo" generated="always" update="false" insert="false" />

And Fluent NHibernate:

Map(x => x.Foo).ReadOnly().Generated.Always();

and potentially this Hibernate forum entry: https://forum.hibernate.org/viewtopic.php?f=1&t=954375

"generated means that the value is being generated by the database. Thus you'd need a trigger, etc actually setting these values."

Related Topic