我有 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
我认为这也会导致保存对象关系时出现一些其他问题。我是否错误配置了映射?我需要做什么才能使其正常工作?
最佳答案
这是你的问题:
<key column="PaymentId" ...
集合的键
应该是InvoiceId。
关于c# - NHibernate 映射创建重复的外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10868216/