开发者

Custom ID generator in NHibernate

HI all,

How to do functionality of generator class="assigned" as well as generator class="native" together.

in my case some situation i will have ID another case i dont know the ID.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Acurus.Capella.Core.DomainObjects" assembly="User">
  <class name="UserLookup, Core" table="User_lookup" lazy="true">
    <id name="Id" column="User_ID">
      <generator class="assigned" />
    </id>


<?xml versi开发者_如何学Con="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Acurus.Capella.Core.DomainObjects" assembly="User">
  <class name="UserLookup, Core" table="User_lookup" lazy="true">
    <id name="Id" column="User_ID">
      <generator class="native" />
    </id>


You can write your own implementation of IIdentifierGenerator using code from both NHibernate.Id.Assigned and whatever concrete implementation of "native" corresponds to your DB, like NHibernate.Id.IdentityGenerator.

However, as Ids should be meaningless, I don't know why you would "have ID" before persisting an entity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜