File tree Expand file tree Collapse file tree 3 files changed +95
-0
lines changed
src/NHibernate.Test/NHSpecificTest/GH3306NullableEntityCorrelatedSubquery Expand file tree Collapse file tree 3 files changed +95
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using NUnit . Framework ;
3
+
4
+ namespace NHibernate . Test . NHSpecificTest . GH3306NullableEntityCorrelatedSubquery
5
+ {
6
+ [ TestFixture ]
7
+ public class Fixture : BugTestCase
8
+ {
9
+ private const string NAME_JOE = "Joe" ;
10
+ private const string NAME_ALLEN = "Allen" ;
11
+
12
+ protected override void OnSetUp ( )
13
+ {
14
+ using var session = OpenSession ( ) ;
15
+ using var tx = session . BeginTransaction ( ) ;
16
+ var joe = new Customer { Name = NAME_JOE } ;
17
+ session . Save ( joe ) ;
18
+
19
+ var allen = new Customer { Name = NAME_ALLEN } ;
20
+ session . Save ( allen ) ;
21
+
22
+ var joeInvoice0 = new Invoice { Customer = joe , Number = 0 } ;
23
+ session . Save ( joeInvoice0 ) ;
24
+
25
+ var allenInvoice1 = new Invoice { Customer = allen , Number = 1 } ;
26
+ session . Save ( allenInvoice1 ) ;
27
+
28
+ tx . Commit ( ) ;
29
+ }
30
+
31
+ protected override void OnTearDown ( )
32
+ {
33
+ using var session = OpenSession ( ) ;
34
+ using var tx = session . BeginTransaction ( ) ;
35
+ session . Delete ( "from Invoice" ) ;
36
+ session . Delete ( "from Customer" ) ;
37
+ tx . Commit ( ) ;
38
+ }
39
+
40
+ [ Test ]
41
+ public void NullableEntityInCorrelatedSubquery ( )
42
+ {
43
+ using var s = OpenSession ( ) ;
44
+ var customers = s . Query < Customer > ( ) . Where ( c => c . Name == NAME_JOE ) ;
45
+ var results = s . Query < Invoice > ( ) . Where ( i => customers . Any ( c => c . Invoices . Any ( ci => ci . Customer == i . Customer ) ) ) . ToList ( ) ;
46
+
47
+ Assert . That ( results . Count , Is . EqualTo ( 1 ) ) ;
48
+ }
49
+ }
50
+ }
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"
3
+ assembly =" NHibernate.Test"
4
+ namespace =" NHibernate.Test.NHSpecificTest.GH3306NullableEntityCorrelatedSubquery" >
5
+
6
+ <class name =" Customer" >
7
+ <id name =" ID" type =" Int32" >
8
+ <generator class =" native" />
9
+ </id >
10
+ <property name =" Name" type =" String" />
11
+
12
+ <set name =" Invoices" inverse =" true" >
13
+ <key column =" CustomerID" />
14
+ <one-to-many class =" Invoice" />
15
+ </set >
16
+ </class >
17
+
18
+ <class name =" Invoice" >
19
+ <id name =" ID" type =" Int32" >
20
+ <generator class =" native" />
21
+ </id >
22
+
23
+ <property name =" Number" type =" Int32" column =" `Number`" />
24
+ <many-to-one name =" Customer" not-found =" ignore" column =" CustomerID" class =" Customer" />
25
+ </class >
26
+
27
+ </hibernate-mapping >
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+
3
+ namespace NHibernate . Test . NHSpecificTest . GH3306NullableEntityCorrelatedSubquery
4
+ {
5
+ public class Customer
6
+ {
7
+ public virtual int ID { get ; protected set ; }
8
+ public virtual ISet < Invoice > Invoices { get ; set ; }
9
+ public virtual string Name { get ; set ; }
10
+ }
11
+
12
+ public class Invoice
13
+ {
14
+ public virtual int ID { get ; protected set ; }
15
+ public virtual Customer Customer { get ; set ; }
16
+ public virtual int Number { get ; set ; }
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments