我无法通过属性关系将我的多个映射到多个。很像这里的问题
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,Culture = neutral,PublicKeyToken = null,对于列: NHibernate.Mapping.Column(QuotationId)
编辑:添加报价映射
public QuotationMapping()
{
Id(x => x.Id).Column("QuotationId");
Map(x => x.ValidUntil);
Map(x => x.Data);
HasMany(x => x.QuotationSKUCosts).KeyColumn("QuotationId");
}
答案 0 :(得分:0)
经过多次寻找后找到答案
.KeyProperty(x => x.Quotation, "QuotationId")
.KeyReference(x => x.QuotationRequestSKU, "QuotationRequestSKUId");
应该是
.KeyReference(x => x.Quotation, "QuotationId")
.KeyReference(x => x.QuotationRequestSKU, "QuotationRequestSKUId");