Model view controller 用confORM映射NHibernate

Model view controller 用confORM映射NHibernate,model-view-controller,nhibernate,mapping,many-to-many,conform,Model View Controller,Nhibernate,Mapping,Many To Many,Conform,我有两门课(为了简洁起见总结): 公共类产品:实体 { ... 公共虚拟IList组件{get;set;} 公共产品(){成分=新列表();} } 及 公共部分类成分:实体 { ... 公共虚拟IList产品{get;set;} 公共成分(){Products=新列表();} } 他们有很多关系,我想: 如果我删除了一种成分,则产品不会被删除,而只删除其列表中的成分 如果我删除一种产品,所有成分都不会被删除 我画了这张地图,但没法用 orm.ManyToMany<

我有两门课(为了简洁起见总结):

公共类产品:实体
{      
...    
公共虚拟IList组件{get;set;}
公共产品(){成分=新列表();}
}

公共部分类成分:实体
{
...
公共虚拟IList产品{get;set;}
公共成分(){Products=新列表();}
}
他们有很多关系,我想:

  • 如果我删除了一种成分,则产品不会被删除,而只删除其列表中的成分
  • 如果我删除一种产品,所有成分都不会被删除
我画了这张地图,但没法用

orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
orm.manytomy();
orm.Cascade(CascadeOn.delete);
我终于明白了。 这是我解决问题的方法,以防帮助更多人:

        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>();
orm=newObjectRelationalMapper();
映射器=新映射器(orm);
//...
类(c=>
{
/*…[映射其他属性]*/
//一方的多对多关系
c、 Bag(p=>p.Products,pm=>pm.Inverse(false),rel=>rel.manytomy());
});
//另一方的多对多关系
orm.manytomy();
orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
        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>();