1
+ using System . Collections . Generic ;
2
+ using Iesi . Collections . Generic ;
3
+
4
+ namespace NHibernate . Test . Events . Collections . Association . Bidirectional . ManyToMany
5
+ {
6
+ public class ParentWithBidirectionalManyToMany : AbstractParentWithCollection
7
+ {
8
+ public ParentWithBidirectionalManyToMany ( ) { }
9
+
10
+ public ParentWithBidirectionalManyToMany ( string name ) : base ( name ) { }
11
+
12
+ public override IChild CreateChild ( string name )
13
+ {
14
+ return new ChildWithBidirectionalManyToMany ( name , new HashedSet < ParentWithBidirectionalManyToMany > ( ) ) ;
15
+ }
16
+
17
+ public override void NewChildren ( ICollection < IChild > children )
18
+ {
19
+ if ( children == Children )
20
+ {
21
+ return ;
22
+ }
23
+ if ( Children != null )
24
+ {
25
+ foreach ( ChildWithBidirectionalManyToMany child in Children )
26
+ {
27
+ child . RemoveParent ( this ) ;
28
+ }
29
+ }
30
+ if ( children != null )
31
+ {
32
+ foreach ( ChildWithBidirectionalManyToMany child in children )
33
+ {
34
+ child . AddParent ( this ) ;
35
+ }
36
+ }
37
+ if ( children == Children )
38
+ {
39
+ return ;
40
+ }
41
+ base . NewChildren ( children ) ;
42
+ }
43
+
44
+ public override void AddChild ( IChild child )
45
+ {
46
+ base . AddChild ( child ) ;
47
+ ( ( ChildWithBidirectionalManyToMany ) child ) . AddParent ( this ) ;
48
+ }
49
+
50
+ public override void AddAllChildren ( ICollection < IChild > children )
51
+ {
52
+ base . AddAllChildren ( children ) ;
53
+ foreach ( ChildWithBidirectionalManyToMany child in children )
54
+ {
55
+ child . AddParent ( this ) ;
56
+ }
57
+ }
58
+
59
+ public override void RemoveChild ( IChild child )
60
+ {
61
+ // Note: if the collection is a bag, the same child can be in the collection more than once
62
+ base . RemoveChild ( child ) ;
63
+ // only remove the parent from the child's set if child is no longer in the collection
64
+ if ( ! Children . Contains ( child ) )
65
+ {
66
+ ( ( ChildWithBidirectionalManyToMany ) child ) . RemoveParent ( this ) ;
67
+ }
68
+ }
69
+
70
+ public override void RemoveAllChildren ( ICollection < IChild > children )
71
+ {
72
+ base . RemoveAllChildren ( children ) ;
73
+ foreach ( ChildWithBidirectionalManyToMany child in children )
74
+ {
75
+ child . RemoveParent ( this ) ;
76
+ }
77
+ }
78
+
79
+ public override void ClearChildren ( )
80
+ {
81
+ if ( Children != null )
82
+ {
83
+ foreach ( ChildWithBidirectionalManyToMany child in Children )
84
+ {
85
+ child . RemoveParent ( this ) ;
86
+ }
87
+ }
88
+ base . ClearChildren ( ) ;
89
+ }
90
+ }
91
+ }
0 commit comments