开发者

Nhibernate Set how to intercept Add() method

开发者 https://www.devze.com 2023-01-06 09:01 出处:网络
I need a solution for this: How to intercept ISet.Add method so I don\'t need to do children.Parent=parent, but jus parent.Children.Add(children);

I need a solution for this: How to intercept ISet.Add method so I don't need to do children.Parent=parent, but jus parent.Children.Add(children);

public开发者_如何学C class MyClass
{
public MyClass Parent;
public ISet<MyClass> Childrens;
}

I want to do this:

var mc = new MyClass();
var mc2 = new MyClass();
mc.Childrens.Add(mc2);

and not

var mc = new MyClass();
var mc2 = new MyClass();
mc.Childrens.Add(mc2);
mc2.Parent=mc;


I simply create an AddChild method which does that.

You could also expose the public property as readonly collection as Frederik demonstrates...

What is the best practice for readonly lists in NHibernate


public IList<MyClass> Childrens
0

精彩评论

暂无评论...
验证码 换一张
取 消