2010-02-24 2 views
0

어떻게하면 NHibernate에서 다음 매핑에 대해 갈까요?
내 엔티티 및 ERD가 아래에 있습니다. 많은 관계를 매핑하는 방법을 알고 있지만 조인 테이블 ReportTargets를 Datapoint 테이블에 매핑하는 방법을 모릅니다. 엄격하게 도메인 엔터티가 아니기 때문에 ReportTargets 엔터티 모델이 없음을 알 수 있습니다. 가장 좋은 해결책은 무엇입니까? 나는 감사합니다 :)의 .. NHibernate에 초보자가 너무 쉽게하시기 바랍니다 갈 생각 MarketReport.Targets으로조인 테이블을 통해 일대 다 관계를 매핑하는 방법은 무엇입니까?

http://img341.imageshack.us/img341/3769/entities.gif

답변

1

이있는 등의 다 대다 매핑 테이블을 가입 할 수 있습니다. 가장 최근의 의견을 바탕으로

<class name="MarketReport"> 
    <id column="reportid" /> 
    <bag name="ReportTargets" table="reporttargets"> 
    <key column="marketreportid"/> 
    <many-to-many column="targetid" class="Target"/> 
    </bag> 
</class> 

<class name="Target"> 
    <id column="targetid" /> 
    <bag name="DataPoints" inverse="true"> 
    <key column="targetid"/> 
    <one-to-many class="DataPoint"/> 
    </bag> 
</class> 

<class name="DataPoint"> 
    <id column="datapointid" /> 
</class> 

는 다음 중 하나가 ternary association, 또는 component collection을하고자합니다. 두 매핑을 모두 포함했습니다.

<class name="MarketReport"> 
    <id column="reportid" /> 
    <map name="ReportTargets" table="reporttargets"> 
     <key column="marketreportid"/> 
     <index-many-to-many column="targetid" class="Target"/> 
     <many-to-many column="datapointid" class="DataPoint"/> 
    </map> 
</class> 

<class name="MarketReport"> 
    <id column="reportid" /> 
    <bag name="ReportTargets" table="reporttargets"> 
     <key column="marketreportid"/> 
     <composite-element class="ReportTarget"> 
      <many-to-one name="Target" column="targetid"/> 
      <many-to-one name="DataPoint" column="datapointid"/> 
     </composite-element> 
    </bag> 
</class> 

<class name="Target"> 
    <id column="targetid" /> 
</class> 

<class name="DataPoint"> 
    <id column="datapointid" /> 
</class> 
+0

안녕하세요 Lachlan, 지속적인 도움에 감사드립니다. 최근의 편집은 Target과 DataPoint 사이에서 직접적인 일대일 작업을 설정합니다. 즉, 같은 조인 테이블을 통해 어떻게 링크를 생성합니까? ReportTargets : MarketReport와 Target 간의 많은 연결에 사용됩니다. 비즈니스 로직은 많은 데이터 포인트가 타겟과 시장보고 사이의 특정 관계와 연관되어 있다는 것입니다. 감사. – Matt