使用 confORM 映射 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>();}
}
具有多对多关系,我想做:
- 如果我删除一种成分,则该产品不会被删除,而只会删除他列表中的成分。
- 如果我删除一种产品,其成分全部不会被删除。
我做了这张地图,但我无法让它工作。
orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
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:
- if I delete one ingredient, the product is not removed but only the ingredient for his list.
- if I delete one product, the ingredients are all without being deleted.
I did this map, but I can't get this to work.
orm.ManyToMany<Product, Ingredient>();
orm.Cascade<Product, Ingredient>(CascadeOn.DeleteOrphans);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于,我明白了。
这是我可以解决这个问题的方法,以防帮助别人更多:
Finally, I got it.
This is the way I could resolve this, in case to help someone more: