【问题标题】:How do I make a self-referencing many-to-many relationship in Fluent NHibernate mapping?如何在 Fluent NHibernate 映射中建立自引用多对多关系?
【发布时间】:2009-08-04 21:04:17
【问题描述】:

谁能告诉我如何使用 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

【问题讨论】:

    标签: nhibernate fluent-nhibernate


    【解决方案1】:

    我相信在这篇文章和现在查看 Fluent NHibernate 之后,这是不可能的。放入 .hbm 文件是完成我在这里想要的唯一方法。

    【讨论】:

      猜你喜欢
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 2012-06-12
      相关资源
      最近更新 更多