简体   繁体   中英

NHibernate 3.3: composite-id with a key-property generated?

I have read that this mapping is not possible in NHibernate 3.3:

<class name="Digital" table="DIGITALS">
    <composite-id>
      <key-many-to-one name="Person" class="Person" column="PERSONID" />
      <key-property name="Id" column="ID">
        **<generator class="increment"/>**
      <key-property/>
    </composite-id>
    <property name="Nombre" column="NOMBRE" />

Basically I need a composite-id's property to be calculated automatically by NH.

Maybe exists a technique to get something similar?

Thanks in advance.

you have to implement it yourself since CompositeIds are always generatedby assigned for NH

class Digital
{
    private static long number = 0;

    private static long NextNumber()
    {
        return Interlocked.Increment(ref number);
    }

    public Digital()
    {
        Id = NextNumber();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM