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 ?
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."
Map(x => x.TicketNumber).
.CustomSqlType("INT IDENTITY(1,1)")
.Not
.Nullable()
.ReadOnly()
.Generated.Insert();
I'm assuming you're trying to use the built in schema generation tool in NHibernate to do this. Unfortunately with this tool, it is impossible to do what you are asking. The only columns it will set the Identity flag for, are the primary key columns. So unless this column is part of the primary key, you will need a manual method to set it to be an Identity column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With