私のプログラムを使用する会社のDepartmentを表す "Lab"というクラスがあります。それには "Employees"という子コレクションがあります。このコレクションには、そのラボに属するすべての従業員が含まれています。 employeeテーブルには、部門に属する部門を表す "Department"という文字列フィールドがあり、Labテーブルには、部門がLabである部門を表す "Department"という文字列フィールドが含まれています。従業員の部門が研究室の部門と一致すると、その従業員はラボに所属します。実際の外部キーがない文字列を使ったNHibernateマッピング
私は、従業員テーブルにLabIDフィールドが含まれている方が望ましいアプローチだと認識していますが、従業員テーブルは自分の管理下になく、変更したくありません。部門と部門が同じ結果を提供するので、私は従業員のマッピングテーブルをラボに追加することなくこれを行うことをお勧めします。
これは、私が使用しようとしている要約マッピングです。返され
<class name="Lab">
<id name="LabID">
<generator class="native" />
</id>
<property name="Department" />
<!--- other properties --->
<set name="Employees" table="Employee_copy" generic="true" inverse="true">
<key column="Department" property-ref="Department" />
<one-to-many class="Employee" />
</set>
</class>
エラーが発生したクエリが正常に実行さ
Identifier type mismatch; Found:<System.Int32> Expected:<System.String> Parameter name: identifier
です。
SELECT employees0_.Department as Department1_, employees0_.EmployeeID as EmployeeID1_, employees0_.EmployeeID as EmployeeID30_0_, employees0_.CommonName as CommonName30_0_, employees0_.LastName as LastName30_0_, employees0_.NetUserID as NetUserID30_0_, employees0_.CompanyID as CompanyID30_0_, employees0_.Department as Department30_0_ FROM Employee employees0_ WHERE employees0_.Department='IS'
私は間違っていますか?
編集:
リバースアソシエーションは正常に機能します。
public virtual int LabID { get; set; }
public virtual string Department { get; set; }
public virtual ISet<Employee> Employees { get; set; }
従業:Objects(オブジェクト) ラボの両方のための
<many-to-one name="Lab" column="Department" property-ref="Department" class="Lab" />
関連するプロパティEmployeeテーブルが不変であることを意図したため
public virtual int EmployeeID { get; protected set; }
public virtual string Department { get; protected set; }
public virtual Lab Lab { get; protected set; }