NHibernate映射创建重复的外键

时间:2012-06-03 05:54:10

标签: c# nhibernate nhibernate-mapping

我有2个POCO映射如下:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="APPayment" table="APPayments">
        <id name="PaymentId">
            <generator class="guid" />
        </id>
        <many-to-one name="Invoice" class="APInvoice" cascade="none" 
            column="InvoiceId" index="ixPaymentInvoice" not-null="true" />
    </class>
    <class name="APInvoice" table="APInvoices">
        <id name="InvoiceId">
            <generator class="guid" />
        </id>
        <bag name="Payments" inverse="true" cascade="none" >
            <key column="PaymentId" foreign-key="fkInvoicePayments" />
            <one-to-many class="APPayment" />
        </bag>
    </class>
</hibernate-mapping>

由于某些原因我无法理解,我在APPayments表上生成了重复的外键:

fk9cdfbf509640182e
fkinvoicepayments

我认为这也会导致一些其他问题,即保存对象关系。我是否错误配置了映射?我需要做些什么才能使其正常工作?

1 个答案:

答案 0 :(得分:2)

这是你的问题:

<key column="PaymentId" ...

集合的key应为 InvoiceId