开发者

Generate identity from seed table in Fluent NHibernate

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>();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜