2

我有 2 个课程(为简洁起见):

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>();}
}

他们有一个多对多的关系,我想做:

  • 如果我删除一种成分,则不会删除产品,而只会删除他列表中的成分。
  • 如果我删除一个产品,所有的成分都不会被删除。

我做了这张地图,但我无法让它工作。

orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
4

1 回答 1

1

终于我明白了。这是我可以解决这个问题的方法,以防更多地帮助别人:

        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>();
于 2011-11-03T22:34:06.823 回答