在Nhibernate中多次映射一列 [英] Mapping a column multiple times in Nhibernate

查看:92
本文介绍了在Nhibernate中多次映射一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个实体.具有以下属性:

I have for example an entity. With the following properties:

public class Entity
{
   public int CustomerId { get; set; }
   public Customer { get; set; } 
}

如何两次映射CustomerId.一次是用于int属性,一次是用于多对一关系?

How can I map the CustomerId twice. Once for the int property and once for the many-to-one relationship ?

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

这是行不通的.我已经尝试过,将它们设置为只读但没有成功.

Just this, doesn't work. I've already tried, making them readonly but no success.

推荐答案

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

One of them should be mapped as readonly (inser/udpate false), and referenced as formula

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

然后它应该可以正常工作.然后,这两个属性都可以用于选择",位置..."的排序方式

Then it should be working correctly. Both properties then can be used for Select, Where... order by

这篇关于在Nhibernate中多次映射一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆