所以,我有一个Invoice
像这样的对象:
public class Invoice
{
public virtual long InvoiceId { get; set; }
public virtual string InvoiceNumber{ get; set; }
public virtual Customer Customer { get; set; }
public virtual Site Site { get; set; }
public virtual IList<InvoiceLineItem> LineItems { get; set; }
public virtual IList<InvoicePayment> Transactions { get; set; }
}
然后,我有一个这样的发票行项目
public class InvoiceLineItem
{
public virtual long InvoiceLineItemId { get; set; }
public virtual Invoice Invoice{ get; set; }
}
最后,发票付款
public class InvoicePayment
{
public virtual long InvoicePaymentId { get; set; }
public virtual Invoice Invoice{ get; set; }
}
问题是,在我的底层架构中InvoicePayment
,我有InvoiceNumber
,SiteId
(到Site
对象)和CustomerId
(到Customer
对象)。
在 InvoiceLineItem 中,我将 InvoiceId 链接回Invoice
.
因此,我的 Invoice 映射如下所示:
public sealed class InvoiceMap : ClassMap<Invoice>
{
public InvoiceMap()
{
Table("InvoiceView");
Id(x => x.InvoiceId).GeneratedBy.Identity();
Map(x => x.InvoiceNumber);
References<Site>(x => x.Site, "SiteId");
References<Customer>(x => x.Customer, "CustomerId");
HasMany<InvoiceLineItem>(x => x.LineItems)
.Inverse();
HasMany<InvoicePayment>(x => x.Transactions)
.KeyColumns.Add("SiteId")
.KeyColumns.Add("EPayCustomerId")
.KeyColumns.Add("InvoiceNumber")
.Inverse();
}
}
订单项映射
public class InvoiceLineItemMap : ClassMap<InvoiceLineItem>
{
public InvoiceLineItemMap()
{
Table("InvoiceLineItems");
Id(x => x.InvoiceLineItemId).GeneratedBy.Identity();
References<FTNI.Core.Model.Invoice.Invoice>(x => x.Invoice, "InvoiceId");
}
}
最后是我的发票付款映射
public class InvoicePaymentMap : ClassMap<InvoicePayment>
{
public InvoicePaymentMap()
{
Table("InvoicePayments");
Id(x => x.InvoicePaymentId).GeneratedBy.Identity();
CompositeId()
.KeyProperty(x => x.Site, "SiteId")
.KeyProperty(x => x.Customer, "CustomerId")
.KeyProperty(x => x.InvoiceNumber);
References<Site>(x => x.Site, "SiteId");
References<EPayCustomer>(x => x.Customer, "CustomerId");
References<FTNI.Core.Model.Invoice.Invoice>(x => x.Invoice)
.Columns("SiteId", "CustomerId", "InvoiceNumber")
.Nullable();
}
}
所以,事实上,我收到了一个错误
外键 (FKE9F746C567E71B3F:InvoiceLineItems [InvoiceId])) 的列数必须与引用的主键 (InvoiceView [SiteId, CustomerId, InvoiceNumber]) 相同
如何调整我的映射,以便加入复合 ID 上的发票付款和身份列上的行项目?