流畅的NHibernate:与产品到产品的多对多关系

时间:2013-06-04 11:04:30

标签: fluent-nhibernate nhibernate-mapping hibernate-mapping

流畅的NHibernate:与Product到Product的多对多关系。我可以在asp.net mvc上实现它

public class Product
{    
       public virtual int Id { get; set; }
       public virtual IList<Product> ManyProduct { get; set; }
}

映射

public class ProductMap : ClassMap<Product>
{    
    public ProductMap()
    {
        Id(x => x.Id);
        Map(x => x.ImageUrl);
    }
    HasManyToMany(x => x.ManyProduct)
         .Cascade.All()
         .Table("ProductInProduct");
}

1 个答案:

答案 0 :(得分:0)

您没有明确说出错误,但您的HasManyToMany定义需要指定ProductInProduct表中的Parent和Child Id列:

HasManyToMany(x => x.ManyProduct)
  .Table("ProductInProduct")
  .ParentKeyColumn("ParentId")
  .ChildKeyColumn("ChildId")
  .Cascade.All();