위탁 예약 소프트웨어로 작업하고 있습니다. 위탁 객체는 다음과 같은 구조가 있습니다NHibernate : 동일한 테이블에 대해 동일한 열에 대해 두 개의 외래 키가 있습니다
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;
}
}
, 스테이션 테이블이있을 것, 그리고 위탁 테이블은 두 개의 지능 것 열 (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>
Consignment.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>
그러나 이상한 이상한 DB 구조가 생성됩니다. XML로 매핑 파일을 많이 작성해야하므로 XML로 매핑해야합니다. 제대로하고 있습니까? 더 좋은 방법이있을 수 있습니까?
감사합니다.
생성 된 DB 구조의 스키마는 무엇입니까? – mickfold