File tree Expand file tree Collapse file tree 4 files changed +122
-0
lines changed
src/NHibernate.Test/OneToOneType Expand file tree Collapse file tree 4 files changed +122
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace NHibernate . Test . OneToOneType
8
+ {
9
+ public class Details
10
+ {
11
+ public virtual int Id { get ; protected set ; }
12
+ public virtual Owner Owner { get ; protected internal set ; }
13
+ public virtual string Data { get ; set ; }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ using NHibernate . Test . NHSpecificTest ;
2
+ using NUnit . Framework ;
3
+
4
+ namespace NHibernate . Test . OneToOneType
5
+ {
6
+ [ TestFixture ]
7
+ public class Fixture : BugTestCase
8
+ {
9
+ protected override void OnTearDown ( )
10
+ {
11
+ using ( var s = Sfi . OpenSession ( ) )
12
+ using ( var tx = s . BeginTransaction ( ) )
13
+ {
14
+ s . CreateQuery ( "delete from Details" ) . ExecuteUpdate ( ) ;
15
+ s . CreateQuery ( "delete from Owner" ) . ExecuteUpdate ( ) ;
16
+
17
+ tx . Commit ( ) ;
18
+ }
19
+ }
20
+
21
+ [ Test ]
22
+ public void OneToOnePersistedOnOwnerUpdate ( )
23
+ {
24
+ object ownerId ;
25
+
26
+ using ( var s = Sfi . OpenSession ( ) )
27
+ using ( var tx = s . BeginTransaction ( ) )
28
+ {
29
+ var owner = new Owner ( )
30
+ {
31
+ Name = "Owner" ,
32
+ } ;
33
+
34
+ ownerId = s . Save ( owner ) ;
35
+
36
+ tx . Commit ( ) ;
37
+ }
38
+
39
+ using ( var s = Sfi . OpenSession ( ) )
40
+ using ( var tx = s . BeginTransaction ( ) )
41
+ {
42
+ Owner owner = s . Load < Owner > ( ownerId ) ;
43
+
44
+ owner . Details = new Details ( )
45
+ {
46
+ Data = "Owner Details"
47
+ } ;
48
+
49
+ tx . Commit ( ) ;
50
+ }
51
+
52
+ using ( var s = Sfi . OpenSession ( ) )
53
+ using ( var tx = s . BeginTransaction ( ) )
54
+ {
55
+ Owner owner = s . Get < Owner > ( ownerId ) ;
56
+
57
+ Assert . NotNull ( owner . Details ) ;
58
+ }
59
+ }
60
+ }
61
+ }
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.OneToOneType" default-lazy =" false" >
3
+ <class name =" Owner" >
4
+ <id name =" Id" unsaved-value =" 0" generator =" native" />
5
+ <property name =" Name" />
6
+ <one-to-one name =" Details" class =" Details" cascade =" all" />
7
+ </class >
8
+
9
+ <class name =" Details" >
10
+ <id name =" Id" unsaved-value =" 0" >
11
+ <generator class =" foreign" >
12
+ <param name =" property" >Owner</param >
13
+ </generator >
14
+ </id >
15
+ <one-to-one name =" Owner" class =" Owner" constrained =" true" />
16
+ <property name =" Data" />
17
+ </class >
18
+ </hibernate-mapping >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace NHibernate . Test . OneToOneType
8
+ {
9
+ public class Owner
10
+ {
11
+ private Details _details ;
12
+
13
+ public virtual int Id { get ; protected set ; }
14
+ public string Name { get ; set ; }
15
+ public virtual Details Details {
16
+ get => _details ;
17
+ set
18
+ {
19
+ _details = value ;
20
+
21
+ if ( _details != null )
22
+ {
23
+ _details . Owner = this ;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments