[英]NHibernate 3.3: composite-id with a key-property generated?
I have read that this mapping is not possible in NHibernate 3.3: 我已经读过这个映射在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. 基本上我需要一个复合id的属性由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 你必须自己实现它,因为CompositeIds总是为NH分配生成
class Digital
{
private static long number = 0;
private static long NextNumber()
{
return Interlocked.Increment(ref number);
}
public Digital()
{
Id = NextNumber();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.