0

私は SQL ビューで作業していますが、NHibernate、ビュー、またはデータベース全般について十分な知識がなく、問題がどこにあるのかを知ることができません。私が使用しているビューには、文字列列「ExemptionCode」がありました。現在、ビューには多くの免除コードが含まれている可能性があります。新しいリレーションの XML マッピングは次のとおりです。

<class name="LatestDocumentVersion" table="LatestDocumentVersion" mutable="false" schema-action="none">
    <id name="DocumentVersionID" type="Int32"/>        
    <property name="ContainerDocumentID" type="Int32"/>
    <!--<property name="ExemptionCode" length="10" />-->
    <set name="ExemptionCodes" cascade="all-delete-orphan" lazy="false" inverse="false">
      <key column="ContainerDocumentID"/>
      <one-to-many class="ContainerDocumentExemptions"/>
    </set>
    <--Properties omitted-->
</class>

ContainerDocumentExemptions クラスのマッピングは次のとおりです。

<class name ="ContainerDocumentExemptions" lazy ="false">
  <id name ="ContainerDocumentExemptionID" type="Int32">
    <generator class="identity"/>
  </id>
  <many-to-one name="ContainerDocumentID" class="ContainerDocuments" column="ContainerDocumentID" cascade="none"/>
  <property name="ExemptionCode" length="10"/>
</class>

ContainerDocumentExemption クラスには、実際には ContainerDocument オブジェクトと双方向の 1 対多の関係があります。もう一方の端は次のとおりです。

<class name="ContainerDocuments" lazy="false" table="ContainerDocuments">
    <id name="ContainerDocumentID" type="Int32">
        <generator class="identity"/>
    </id>
    <!--<property name="ExemptionCode" length="10" />-->
    <set name="Exemptions" cascade="all-delete-orphan" lazy="false" inverse="true">
      <key column="ContainerDocumentID"/>
      <one-to-many class="ContainerDocumentExemptions"/>
    </set>
    <--Properties omitted-->
</class>

この行を ContainerDocuments クラスに追加すると、ContainerDocuments は新しい ContainerDocumentExemptions テーブルに対して正しく読み書きできるようになります。

public class ContainerDocuments {
    public virtual ISet<ContainerDocumentExemptions> Exemptions { get; set; }
    //Properties omitted
}

そこで、次のコードを LatestDocumentVersion クラスに追加しました。

public class LatestDocumentVersion {
    public virtual int ContainerDocumentID { get; set; }
    public virtual ISet<ContainerDocumentExemption ExemptionCodes { get; set; }
    //properties omitted
}

LatestDocumentVersion は、さまざまなテーブルの束に対して内部結合と外部結合を実行し、それぞれからさまざまな列を取得するビューです。(ビューを作成する SQL は非常に複雑であり、当面の問題とは無関係であることを願っています。) 新しく追加された LatestDocumentVersion.ContainerDocumentID は、ContainerDocumentExemptions テーブルへの外部キーであり、常に正しく入力されます。ただし、ExemptionCodes コレクションは常に空のままです。

問題の一部は、ContainerDocumentExemptions クラスの ContainerDocument 後方参照にあると感じています。これにより、LatestDocumentVersion クラスで同じマッピングを使用できなくなる可能性がありますか? 問題がある場合は、LatestDocumentVersion-ContainerDocumentExemptions 関係を一方向にすることで、その問題が軽減されると考えました。では、LatestDocumentVersion.ExemptionCodes フィールドにデータを入力するにはどうすればよいでしょうか?? 問題をデバッグする方法について、誰かが少なくとも私にヒントを与えることができますか?

4

1 に答える 1

1

ContainerDocumentIDはクラスの ID ですが、ContainerDocumentクラスにはありません。LatestDocumentVersionデフォルトでは、各 1 対多が ID に結合されます。マッピングproperty-refに追加LatestDocumentVersion

<class name="LatestDocumentVersion" table="LatestDocumentVersion" mutable="false" schema-action="none">
    <id name="DocumentVersionID" />
    <property name="ContainerDocumentID"/>
    <set name="ExemptionCodes" cascade="all-delete-orphan" lazy="false" inverse="false">
      <key column="ContainerDocumentID" property-ref="ContainerDocumentID"/>
      <one-to-many class="ContainerDocumentExemptions"/>
    </set>
</class>
于 2013-02-13T19:30:21.110 に答える