Reputation: 1
two entities's mapping files as follow,I want to build ont-to-many relation for two entities but the "one" entity's column is not the key column.Because of the DB table could not change, Could I have a method to build it.Please help me,thx.
<class name ="Sue" table="[Sue]">
<id name="ID" column ="ID" type="Guid" />
<property name="SueSmallType">
<column name="SueSmallType" sql-type ="nvarchar(Max)" />
</property>
</class>
<class name ="SueType" table="[SueType]">
<id name="ID" column ="ID" type="Guid" />
<property name="Code">
<column name="Code" sql-type ="nvarchar(Max)" />
</property>
</class>
for example build the relation to "SueSmallType" and "Code",what should I do.
Upvotes: 0
Views: 107
Reputation: 30813
property-ref is there for this scenario, but you'll loose lazyloading because "SueSmallType" is not the Id of the referenced object.
<class name ="Sue" table="[Sue]">
<id name="ID" column ="ID" type="Guid" />
<many-to-one name="SueType" column="SueSmallType" property-ref="Code"/>
</class>
<class name ="SueType" table="[SueType]">
<id name="ID" column ="ID" type="Guid" />
<property name="Code">
<column name="Code" length="8000" />
</property>
</class>
note the length property over a certan threshold (8000 for example) has the same effect as setting the sqltype to the databases long text type (nvarchar(max), text)
Upvotes: 1