在Nhibernate中多次映射列

在Nhibernate中多次映射列,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,例如,我有一个实体。具有以下特性: public class Entity { public int CustomerId { get; set; } public Customer { get; set; } } 如何将CustomerId映射两次。一次用于int属性,一次用于多对一关系 <many-to-one name="Customer" column="[CustomerId]" class="Customer"/> <property name="C

例如,我有一个实体。具有以下特性:

public class Entity
{
   public int CustomerId { get; set; }
   public Customer { get; set; } 
}
如何将CustomerId映射两次。一次用于int属性,一次用于多对一关系

<many-to-one name="Customer" column="[CustomerId]" class="Customer"/>
<property name="CustomerId" column="[CustomerId]" type="Int64" />


就这样,不行。我已经尝试过了,使它们成为只读的,但没有成功。

其中一个应该映射为只读(inser/udpate false),并引用为
公式

<many-to-one name="Customer" column="[CustomerId]" class="Customer"/>
<property name="CustomerId" formula="[CustomerId]" type="Int64" insert="false" update="false" />


那么它应该能正常工作。这两个属性都可以用于选择,其中。。。order by

您不需要映射CustomerId,您可以通过Customer.CustomerId访问它。如果您使用的是延迟加载,那么CustomerId将填充到代理对象中,因此它始终可用,而不会触发额外的选择

如果必须公开它,请将其作为可为空的只读属性公开:

   public Customer { get; set; } 
   public int? CustomerId
   {
       get { return Customer == null ? (int?)null: Customer.CustomerId }
   }