2009-08-04 9 views
0

Fluent NHibernateを使用してこのマッピングを実行する方法を教えてもらえますか?これは単に複合テーブルを持つアカウントテーブルです。複合テーブルには多くの子アカウントがあります。ここで Fluent NHibernateマッピングで自己参照の多対多の関係を作成するにはどうすればよいですか?

は作業NHibernateのマッピングだとそれが生成するSQLを作成します。

<?xml version="1.0"?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> 
<class name="NHibernateM2M000.Account, NHibernateM2M000" lazy="false"> 
    <composite-id> 
     <key-property type="Int32" name="AccountId" /> 
     <key-property type="Char" name="AccountTypeAbbr" /> 
    </composite-id> 
    <property name="Name" column="AccountName" /> 
    <bag name="ChildAccounts" lazy="false" table="AccountXref"> 
     <key> 
      <column name="ParentAccountId" sql-type="int" /> 
      <column name="ParentAccountTyper" sql-type="nchar" length="1" /> 
     </key> 
     <many-to-many class="NHibernateM2M000.Account, NHibernateM2M000"> 
      <column name="ChildAccountId" sql-type="int"/> 
      <column name="ChildAccountType" sql-type="nchar" length="1" />    
     </many-to-many> 
    </bag> 
</class> 

create table Account (AccountId INT not null, AccountTypeAbbr NCHAR(1) not null, AccountName NVARCHAR(255) null, primary key (AccountId, AccountTypeAbbr)) 

create table AccountXref (ParentAccountId int not null, ParentAccountTyper nchar not null, ChildAccountId int not null, ChildAccountType nchar not null) 

alter table AccountXref add constraint FKB769F8B52F1320AB foreign key (ChildAccountId, ChildAccountType) references Account 

alter table AccountXref add constraint FKB769F8B5A2DB3DC7 foreign key (ParentAccountId, ParentAccountTyper) references Account 

答えて

0

私はそれは不可能だと、今、この投稿の時点で流暢NHibernateのを見た後信じて、 。 .hbmファイルにドロップすることは私がここで望んでいたことを達成する唯一の方法です。

関連する問題