我有这样的数据库表:
[表记录]
RecordId MyColumn1 MyColumn2
----------------------------------
112 somedata8 somedata7
112 somedata6 somedata1
148 somedata3 somedata5
[tbl记录水果]
RecordId FruitTypeId
-------------------------
112 53
112 85
148 16
[表水果类型]
FruitTypeId Text
----------------------
53 Apple
85 Banana
16 Orange
以及对应的NHibernate映射:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Record, Infrastructure.Interface"
table="tblRecord">
<id name="Id" type="Int32" unsaved-value="null">
<column name="RecordId" length="4" sql-type="int" not-null="true" unique="true" index="PK_tblRecord" />
<generator class="native" />
</id>
...
<bag name="Fruits" table="tblRecordFruit" inverse="false" lazy="true" cascade="save-update">
<key>
<column name="RecordId" length="4" sql-type="int" not-null="true" />
</key>
<many-to-many
class="FruitType, Infrastructure.Interface">
<column name="FruitTypeId" length="2" sql-type="smallint" not-null="true" />
</many-to-many>
</bag>
...
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="FruitType, Infrastructure.Interface"
table="tblFruitType"
mutable="false"
lazy="false">
<id name="Id" type="Int16" unsaved-value="0">
<column name="FruitTypeID" sql-type="smallint" not-null="true" unique="true" index="PK_Fruit" />
<generator class="native" />
</id>
<property name="Text" type="String">
<column name="Text" length="255" sql-type="varchar" not-null="true" />
</property>
</class>
</hibernate-mapping>
绝地无双
白猪掌柜的
相关分类