2

가 준수와 함께 :매핑 NHibernate에 내가 (간결하게 요약) 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>();} 
} 

그들은이 ManyToMany 관계를 가지고 있고, 내가하고 싶은 :

  • 성분 하나를 지우면 제품이 제거되지 않고 성분 목록에 들어 있습니다.
  • 하나의 제품을 삭제하면 성분이 모두 삭제되지 않습니다.

이지도를 만들었지 만 작동하지 않습니다.

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

답변

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