In NHibernate 1.2 is it possible to have the ID generated by a database trigger? Basically we need to change one of our tables to stop using a sequence and instead use a trigger to generate the primary key. So obviously I need to update the nhibernate mapping to use a different generator class but I'm not sure what class I should use, or even if this is supported in开发者_JS百科 1.2. Any help would be greatly appreciated. Thanks!
NHibernate allows you to do this but only starting from 2.1.0:
trigger-identity
The “trigger-identity” is a NHibernate specific feature where the POID is generated by the RDBMS at the INSERT query trough a BEFORE INSERT trigger. In this case you can use any supported type, including custom type, with the limitation of “single-column” (so far)...
select
The “select” generator is a deviation of the “trigger-identity”. This generator work together with natural-id feature. The difference “trigger-identity” is that the POID value is retrieved by a SELECT using the natural-id fields as filter...
If you don't want to upgrade to later versions of NHibernate (because of .NET 1.1?) then you can try Ayende's custom dialect solution or extend NHibernate as suggested here.
精彩评论