如何将同一属性映射到同一个表上的不同列

时间:2010-11-08 11:35:37

标签: nhibernate

<property name="Registration" column="vrn" type="String" length="16" />
    <property name="Vin" column="vin" type="String" length="32" />
    <property name="EngineCapacity" column="engineCapacityCC" type="Int32" />
    <property name="Make" column="make" type="String" length="128" />
    <property name="ModelDescription" column="modelDescription" type="String" length="128" />
    <property name="ModelCode" column="modelCode" type="String" length="128" />**
    <property name="RegistrationDate" column="registrationDate" type="DateTime" />
    <property name="Manufacturer" column="manufacturer" type="String" length="128" />
    <property name="ManufactureDate" column="manufactureDate" type="DateTime" />
    <property name="Range" column="range" type="String" length="128" />**
    <property name="DriveType" column="driveType" type="String" length="1" />
    <property name="BodyType" column="bodyType" type="String" length="25" />
    <property name="EngineType" column="engineType" type="String" length="25" />
    <property name="Colour" column="colour" type="String" length="25" />
    <property name="IsImported" column="IsImported" type="Boolean" />
    <property name="IsLeftHandDrive" column="IsLeftHandDrive" type="Boolean" />
    <property name="Range" column="ClientRangeCode" type="String" />**
    <property name="ModelCode" column="ClientModelCode" type="String" />**
    <property name="IsTaxi" column="IsTaxi" type="Boolean" />

此映射引发和异常(重复属性......)

我需要将ModelCode映射到ClientModelCode和modelCode列

我需要为属性Range

做同样的事情

感谢

1 个答案:

答案 0 :(得分:3)

你做不到。在类中多次定义相同的属性名称是不可能的,也没有意义。您的类应具有ModelCode和ClientModelCode的单独属性。

另一个选择是拥有ModelCode和ClientModelCode的私有成员,并通过公共ModelCode属性公开一个。