首页 文章

使用属性进行多对多映射 - 主键是外键

提问于
浏览
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,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");
    }

1 回答

  • 0

    经过深思熟虑后找到了答案

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

    应该

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

相关问题