I have 2 classes (summarized for brevity) :
public class Product : Entity<Guid>
{
...
public virtual IList<Ingredient> Ingredients { get; set; }
public Product(){Ingredients = new List<Ingredient>();}
}
and
public partial class Ingredient : Entity<int>
{
...
public virtual IList<Product> Products { get; set; }
public Ingredient(){Products = new List<Product>();}
}
They have a ManyToMany relationship, and I want to do:
I did this map, but I can't get this to work.
orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
Finally, I got it. This is the way I could resolve this, in case to help someone more:
orm = new ObjectRelationalMapper();
mapper = new Mapper(orm);
//...
mapper.Class<Ingredient>(c =>
{
/* ...[MAP OTHERS PROPERTY]...*/
// Many to many relationship in One side
c.Bag(p => p.Products, pm => pm.Inverse(false), rel => rel.ManyToMany());
});
// Many to many relationship in other side
orm.ManyToMany<Product, Ingredient>();