【发布时间】:2013-04-12 06:54:37
【问题描述】:
我正在开发寄售预订软件。 寄售对象的结构如下:
public class Consignment
{
//Other properties
public virtual Station FromStation{get;set;}
public virtual Station ToStation{get;set;}
}
这里是车站对象:
public class Station
{
public virtual int StationId{get;set;}
public virtual string StationName{get;set;}
//I don't want this property but I have to keep it.
public virtual Iesi.Collections.Generic.ISet<Consginment> ConsginmentFrom
{
get;
set;
}
//I don't want this property but I have to keep it here.
public virtual Iesi.Collections.Generic.ISet<Consginment> ConsginmentTo
{
get;
set;
}
}
在数据库端,会有一个 Station 表,而 Consignment 表会有两个 int 列(分别称为 FromStation 和 ToStation),用于存储车站的 id。
我不是一个 NHibernate 人,在谷歌搜索和阅读半天后,我想出了以下映射文件:
Station.hbm.xml
<class name="Station" table="Station">
<id name="StationId" >
<column name="STATION_ID" not-null="true" />
<generator class="identity" />
</id>
<property name="StationName" >
<column name="STATION_NAME" not-null="true" />
</property>
<set name="ConsginmentFrom" inverse="true" lazy="true" generic="true">
<key>
<column name="StationId" />
</key>
<one-to-many class="Consignment" />
</set>
<set name="ConsignmentTo" inverse="true" lazy="false" generic="true">
<key>
<column name="StationId" />
</key>
<one-to-many class="Consignment" />
</set>
</class>
寄售.hbm.xml
<class name="Consignment" abstract="true"
table="Consignment" lazy="false">
<id name="ConsignmentId">
<generator class="hilo"/>
</id>
<!--Column mapping for other properties-->
<many-to-one name="FromStation" class="Station">
<column name="STATION_ID" not-null="true" />
</many-to-one>
<many-to-one name="ToStation" class="Station">
<column name="STATION_ID" not-null="true" />
</many-to-one>
</class>
但上面生成了奇怪的数据库结构。 我必须做 xml 映射文件,因为很多已经用 xml 编写了。 我做得对吗?有没有更好的办法?
感谢您阅读本文。
【问题讨论】:
-
生成的数据库结构的架构是什么?
标签: c#-4.0 nhibernate nhibernate-mapping