fluent NHibernate: many-to-many relationship with Product to Product

为君一笑 提交于 2020-01-05 10:18:07

问题


fluent NHibernate: many-to-many relationship with Product to Product.how i can implement it on asp.net mvc

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

Mapping

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

回答1:


You don't specifically say what is wrong but your HasManyToMany definition needs to specify the Parent and Child Id columns from your ProductInProduct table:

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


来源:https://stackoverflow.com/questions/16916185/fluent-nhibernate-many-to-many-relationship-with-product-to-product

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!