File tree Expand file tree Collapse file tree 4 files changed +157
-0
lines changed Expand file tree Collapse file tree 4 files changed +157
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+
4
+ namespace NHibernate . Test . NHSpecificTest . NH3480
5
+ {
6
+ class Entity
7
+ {
8
+ public Entity ( )
9
+ {
10
+ Children = new HashSet < Child > ( ) ;
11
+ }
12
+
13
+ public virtual Key Id { get ; set ; }
14
+ public virtual string Name { get ; set ; }
15
+ public virtual int OtherId { get ; set ; }
16
+ public virtual ISet < Child > Children { get ; set ; }
17
+
18
+ public override bool Equals ( object obj )
19
+ {
20
+ if ( obj is Entity )
21
+ {
22
+ var otherEntity = ( Entity ) obj ;
23
+ return otherEntity . Id . Equals ( this . Id ) ;
24
+ }
25
+ return false ;
26
+ }
27
+
28
+ public override int GetHashCode ( )
29
+ {
30
+ return Id . GetHashCode ( ) ;
31
+ }
32
+
33
+ public class Key
34
+ {
35
+ public virtual Guid Id { get ; set ; }
36
+
37
+ public override bool Equals ( object obj )
38
+ {
39
+ if ( obj is Key )
40
+ {
41
+ var otherEntity = ( Key ) obj ;
42
+ return otherEntity . Id . Equals ( this . Id ) ;
43
+ }
44
+ return false ;
45
+ }
46
+
47
+ public override int GetHashCode ( )
48
+ {
49
+ // Needed to reproduce the problem
50
+ return 20 . GetHashCode ( ) ;
51
+ }
52
+ }
53
+ }
54
+
55
+ class Child
56
+ {
57
+ public virtual Guid Id { get ; set ; }
58
+ public virtual string Name { get ; set ; }
59
+ public virtual Entity Parent { get ; set ; }
60
+ }
61
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Linq ;
3
+ using NHibernate . Linq ;
4
+ using NHibernate . Collection ;
5
+ using NUnit . Framework ;
6
+
7
+ namespace NHibernate . Test . NHSpecificTest . NH3480
8
+ {
9
+ [ TestFixture ]
10
+ public class Fixture : BugTestCase
11
+ {
12
+ public override string BugNumber
13
+ {
14
+ get { return "NH3480" ; }
15
+ }
16
+
17
+ protected override void OnSetUp ( )
18
+ {
19
+ using ( ISession session = OpenSession ( ) )
20
+ {
21
+ using ( ITransaction transaction = session . BeginTransaction ( ) )
22
+ {
23
+ var parent1 = new Entity { Id = new Entity . Key ( ) { Id = Guid . NewGuid ( ) } , Name = "Bob" , OtherId = 20 } ;
24
+ session . Save ( parent1 ) ;
25
+
26
+ var child1 = new Child { Name = "Bob1" , Parent = parent1 } ;
27
+ session . Save ( child1 ) ;
28
+
29
+ var child2 = new Child { Name = "Bob2" , Parent = parent1 } ;
30
+ session . Save ( child2 ) ;
31
+
32
+ session . Flush ( ) ;
33
+ transaction . Commit ( ) ;
34
+ }
35
+ }
36
+ }
37
+
38
+ protected override void OnTearDown ( )
39
+ {
40
+ using ( ISession session = OpenSession ( ) )
41
+ {
42
+ using ( ITransaction transaction = session . BeginTransaction ( ) )
43
+ {
44
+ session . Delete ( "from System.Object" ) ;
45
+
46
+ session . Flush ( ) ;
47
+ transaction . Commit ( ) ;
48
+ }
49
+ }
50
+ }
51
+
52
+ [ Test ]
53
+ public void Test ( )
54
+ {
55
+ using ( ISession session = OpenSession ( ) )
56
+ {
57
+ using ( session . BeginTransaction ( ) )
58
+ {
59
+ var result = from e in session . Query < Entity > ( )
60
+ where e . Name == "Bob"
61
+ select e ;
62
+ var entity = result . Single ( ) ;
63
+
64
+ NHibernateUtil . Initialize ( entity . Children ) ;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <hibernate-mapping xmlns =" urn:nhibernate-mapping-2.2" assembly =" NHibernate.Test" namespace =" NHibernate.Test.NHSpecificTest.NH3480" >
3
+
4
+ <class name =" Entity" >
5
+ <composite-id name =" Id" >
6
+ <key-property name =" Id" />
7
+ </composite-id >
8
+ <property name =" Name" not-null =" true" />
9
+ <property name =" OtherId" unique =" true" not-null =" true" />
10
+ <set name =" Children" cascade =" all-delete-orphan" inverse =" true" >
11
+ <key property-ref =" OtherId" column =" Parent" />
12
+ <one-to-many class =" Child" />
13
+ </set >
14
+ </class >
15
+
16
+ <class name =" Child" >
17
+ <id name =" Id" generator =" guid.comb" />
18
+ <property name =" Name" not-null =" true" />
19
+ <many-to-one name =" Parent" property-ref =" OtherId" not-null =" true" />
20
+ </class >
21
+
22
+ </hibernate-mapping >
Original file line number Diff line number Diff line change 691
691
<Compile Include =" NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
692
692
<Compile Include =" Linq\ByMethod\DistinctTests.cs" />
693
693
<Compile Include =" Component\Basic\ComponentWithUniqueConstraintTests.cs" />
694
+ <Compile Include =" NHSpecificTest\NH3480\Entity.cs" />
695
+ <Compile Include =" NHSpecificTest\NH3480\Fixture.cs" />
694
696
<Compile Include =" NHSpecificTest\NH3487\Entity.cs" />
695
697
<Compile Include =" NHSpecificTest\NH3487\Fixture.cs" />
696
698
<Compile Include =" NHSpecificTest\NH3570\BiFixture.cs" />
3068
3070
<EmbeddedResource Include =" NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
3069
3071
</ItemGroup >
3070
3072
<ItemGroup >
3073
+ <EmbeddedResource Include =" NHSpecificTest\NH3480\Mappings.hbm.xml" >
3074
+ <SubType >Designer</SubType >
3075
+ </EmbeddedResource >
3071
3076
<EmbeddedResource Include =" NHSpecificTest\NH3570\Mappings.hbm.xml" />
3072
3077
<EmbeddedResource Include =" NHSpecificTest\NH3455\Mappings.hbm.xml" />
3073
3078
<EmbeddedResource Include =" NHSpecificTest\NH3590\Mappings.hbm.xml" />
You can’t perform that action at this time.
0 commit comments