I need to generate an identity from a column in a seed table and increment the value in that column开发者_StackOverflow中文版.
e.g
Seed Table:
name "analysisid"
id 1
Analysis Table:
id
name
description
On the analysis mapping I need to ensure that the id is taken from the seed table and on inserting an analysis the analysisid of the seedid is updated.Do I implement a custom class inheriting from TableGenerator?
NHibernate includes a number of identity generation strategies, and includes an extension mechanism for custom ones via NHibernate.Id.IIdentifierGenerator
.
You could do this by implementing an insert trigger which fetches and assigns the next identifier for entity Analysis. In this case use <generator class="trigger-identity" />
.
Another approach is to build your own identifier strategy by implementing IIdentifierGenerator
and mapping as <generator class="My.Namespace.MyIdentifierGenerator" />
.
In fluent, those generators are mapped by:
Id( x => x.Id ).GeneratedBy.Custom<NHibernate.Id.TriggerIdentityGenerator>();
Id( x => x.Id ).GeneratedBy.Custom<My.Namespace.MyIdentifierGenerator>();
精彩评论