1

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");
}
rouen
  • 5,003
  • 2
  • 25
  • 48
smart boy
  • 671
  • 4
  • 11
  • 24

1 Answers1

0

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();
connectedsoftware
  • 6,987
  • 3
  • 28
  • 43