bidi associations nhibernate mapping
i have classes bidiparent bidichildlist couple family children bidirectional parent-child relationship. child's progenitor updated e.g. use layer, aged new parents' children lists automatically updated simulate change. likewise, parent's children list updated e.g. adding new child, child's progenitor automatically altered aged parent's children list. i wish try build adult "smart" domain model.
first question, obviously, is: even good idea?
second doubt is: illusory tell nhibernate opening cgange field _children _parent, nonetheless cruise property children progenitor wholly synonymous field? nhibernate should bucket save middle fields, nonetheless hql linq queries should open properties?
public category bidiparent<c, p> { ... }
public category bidichildlist<c, p> : ilist<c> { ... }
public category progenitor {
open twine name { get; set; }
open ilist<child> children {
{ relapse childrenbidi; }
set { childrenbidi.set(value); }
}
private bidichildlist<child, parent> childrenbidi {
{ relapse bidichildlist.create(this, p => p._children, c => c._parent, (c, p) => c._parent = p); }
}
middle ilist<child> _children = new list<child>();
}
public category child {
open twine name { get; set; }
open progenitor parent {
{ relapse parentbidi.get(); }
set { parentbidi.set(value); }
}
private bidiparent<child, parent> parentbidi {
{ relapse bidiparent.create(this, p => p._children, () => _parent, p => _parent = p); }
}
middle progenitor _parent = null;
}
[test]
public vacant multilevelconstruction_succeeds() {
var p = new progenitor {
name = "bob",
children = new list<child> {
new child { name = "kate" },
new child { name = "billy" }
}
};
assert.areequal(2, p.children.count);
assert.areequal("kate", p.children[0].name);
assert.areequal("billy", p.children[1].name);
assert.aresame(p, p.children[0].parent);
assert.aresame(p, p.children[1].parent);
}
Comments
Post a Comment