0
我在使用屬性關係映射多對多時遇到了問題。就像這裏的問題具有屬性的多對多映射 - 主鍵是外鍵
fluent nhibernate - Many to Many mapping with attribute
但是我沒有在我的中產階級的一個主鍵,取而代之的則是由其他兩個班的ID的。
報價SKU類(中產階級)
public class QuotationSKUCost : Entity
{
public virtual decimal UnitPrice { get; set; }
public virtual Quotation Quotation { get; set; }
public virtual QuotationRequestSKU QuotationRequestSKU { get; set; }
}
報價類
public class Quotation : Entity
{
public virtual int Id { get; set; }
public virtual DateTime ValidUntil { get; set; }
public virtual string Data { get; set; }
public virtual ICollection<QuotationSKUCost> QuotationSKUCosts { get; set; }
}
報價請求SKU
public class QuotationRequestSKU : Entity
{
public virtual int Id { get; set; }
public virtual int Quantity { get; set; }
public virtual ICollection<QuotationSKUCost> QuotationSKUCost { get; set; }
}
中產階級映射!!
public QuotationSKUCostMapping()
{
Table("QuotationSKUCost");
CompositeId() //need to map QuotationId and QuotationRequestSKUid as Composite key
.KeyProperty(x => x.Quotation, "QuotationId")
.KeyReference(x => x.QuotationRequestSKU, "QuotationRequestSKUId");
Map(x => x.UnitPrice);
}
嘗試調試時,我得到的錯誤是:
無法確定類型:ORM.Entities.Quote.Quotation,ORM, 版本= 1.0.0.0,文化=中性公鑰=空,爲列: NHibernate.Mapping.Column(QuotationId)
編輯:添加報價馬pping
public QuotationMapping()
{
Id(x => x.Id).Column("QuotationId");
Map(x => x.ValidUntil);
Map(x => x.Data);
HasMany(x => x.QuotationSKUCosts).KeyColumn("QuotationId");
}
什麼是你的'Quotation'類的配置? – Guillaume
我已經添加了引用映射 – Steve