2009-08-04 66 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文件是完成我想要的东西的唯一方法。

相关问题