0

我无法使用属性关系映射我的多对多。很像这里的问题

fluent nhibernate - 具有属性的多对多映射

但是我的中产阶级没有主键,而是由其他两个班级的 ID 组成。

报价单品类(中类)

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、Version=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");
    }
4

1 回答 1

0

看了很久才找到答案

          .KeyProperty(x => x.Quotation, "QuotationId")
          .KeyReference(x => x.QuotationRequestSKU, "QuotationRequestSKUId");

应该

          .KeyReference(x => x.Quotation, "QuotationId")
          .KeyReference(x => x.QuotationRequestSKU, "QuotationRequestSKUId");
于 2012-10-09T10:54:08.993 回答