我有两门课(简略地总结):
public class Product : Entity<Guid>
{
...
public virtual IList<Ingredient> Ingredients { get; set; }
public Product(){Ingredients = new List<Ingredient>();}
}和
public partial class Ingredient : Entity<int>
{
...
public virtual IList<Product> Products { get; set; }
public Ingredient(){Products = new List<Product>();}
}他们有ManyToMany关系,我想做的是:
我做了这张地图,但我不能让它起作用。
orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);发布于 2011-11-03 22:34:06
终于,我明白了。为了帮助更多的人,我可以这样解决这个问题:
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>();https://stackoverflow.com/questions/7929348
复制相似问题