@@ -53,68 +53,75 @@ protected override HbmMapping GetMappings()
53
53
return mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
54
54
}
55
55
56
- [ Test ]
57
- public async Task SubqueryCorrelatedThroughConditionalAsync ( )
56
+ protected override void OnSetUp ( )
58
57
{
59
58
using ( var session = OpenSession ( ) )
60
59
using ( var transaction = session . BeginTransaction ( ) )
61
60
{
62
- // data
63
- {
64
- // alpha entities
65
- var projectAlpha = new Project { Name = "Alpha" } ;
66
- await ( session . SaveAsync ( projectAlpha ) ) ;
61
+ // alpha entities
62
+ var projectAlpha = new Project { Name = "Alpha" } ;
63
+ session . Save ( projectAlpha ) ;
67
64
68
- var componentAlpha = new Component { Project = projectAlpha , Name = "Thingie" } ;
69
- await ( session . SaveAsync ( componentAlpha ) ) ;
65
+ var componentAlpha = new Component { Project = projectAlpha , Name = "Thingie" } ;
66
+ session . Save ( componentAlpha ) ;
70
67
71
- var tagAlpha = new Tag { Component1 = componentAlpha , Name = "A20" } ;
72
- await ( session . SaveAsync ( tagAlpha ) ) ;
68
+ var tagAlpha = new Tag { Component1 = componentAlpha , Name = "A20" } ;
69
+ session . Save ( tagAlpha ) ;
73
70
74
- // beta entities
75
- var projectBeta = new Project { Name = "Beta" } ;
76
- await ( session . SaveAsync ( projectBeta ) ) ;
71
+ // beta entities
72
+ var projectBeta = new Project { Name = "Beta" } ;
73
+ session . Save ( projectBeta ) ;
77
74
78
- var componentBeta = new Component { Project = projectBeta , Name = "Thingie" } ;
79
- await ( session . SaveAsync ( componentBeta ) ) ;
75
+ var componentBeta = new Component { Project = projectBeta , Name = "Thingie" } ;
76
+ session . Save ( componentBeta ) ;
80
77
81
- var tagBeta = new Tag { Component1 = componentBeta , Name = "B17" } ;
82
- await ( session . SaveAsync ( tagBeta ) ) ;
83
- }
78
+ var tagBeta = new Tag { Component1 = componentBeta , Name = "B17" } ;
79
+ session . Save ( tagBeta ) ;
84
80
85
- await ( session . FlushAsync ( ) ) ;
81
+ transaction . Commit ( ) ;
82
+ }
83
+ }
86
84
87
- // query
88
- {
89
- ICriteria tagCriteria = session . CreateCriteria ( typeof ( Tag ) , "t" ) ;
90
- tagCriteria . CreateCriteria ( "Component1" , "c1" ) ;
91
- tagCriteria . CreateCriteria ( "Component2" , "c2" , JoinType . LeftOuterJoin ) ;
85
+ protected override void OnTearDown ( )
86
+ {
87
+ using ( var session = OpenSession ( ) )
88
+ using ( var transaction = session . BeginTransaction ( ) )
89
+ {
90
+ session . CreateQuery ( "delete from System.Object" ) . ExecuteUpdate ( ) ;
91
+ transaction . Commit ( ) ;
92
+ }
93
+ }
92
94
93
- IProjection projectNameProjection ;
94
- {
95
- // create correlated subquery
96
- var projectCriteria = DetachedCriteria . For ( typeof ( Project ) , "p" ) ;
95
+ [ Test ]
96
+ public async Task SubqueryCorrelatedThroughConditionalAsync ( )
97
+ {
98
+ using ( var session = OpenSession ( ) )
99
+ using ( session . BeginTransaction ( ) )
100
+ {
101
+ var tagCriteria = session . CreateCriteria ( typeof ( Tag ) , "t" ) ;
102
+ tagCriteria . CreateCriteria ( "Component1" , "c1" ) ;
103
+ tagCriteria . CreateCriteria ( "Component2" , "c2" , JoinType . LeftOuterJoin ) ;
97
104
98
- var conditionalCorrelationProjection = Projections . Conditional (
99
- Restrictions . IsNotNull ( Projections . Property ( "t.Component2" ) ) ,
100
- Projections . Property ( "c2.Project" ) ,
101
- Projections . Property ( "c1.Project" ) ) ;
102
- projectCriteria . Add ( Restrictions . EqProperty ( "p.Id" , conditionalCorrelationProjection ) ) ;
105
+ // create correlated subquery
106
+ var projectCriteria = DetachedCriteria . For ( typeof ( Project ) , "p" ) ;
103
107
104
- projectCriteria . SetProjection ( Projections . Property ( "p.Name" ) ) ;
108
+ var conditionalCorrelationProjection = Projections . Conditional (
109
+ Restrictions . IsNotNull ( Projections . Property ( "t.Component2" ) ) ,
110
+ Projections . Property ( "c2.Project" ) ,
111
+ Projections . Property ( "c1.Project" ) ) ;
112
+ projectCriteria . Add ( Restrictions . EqProperty ( "p.Id" , conditionalCorrelationProjection ) ) ;
105
113
106
- projectNameProjection = Projections . SubQuery ( projectCriteria ) ;
107
- }
114
+ projectCriteria . SetProjection ( Projections . Property ( "p.Name" ) ) ;
108
115
109
- tagCriteria . Add ( Restrictions . Eq ( projectNameProjection , "Beta" ) ) ;
110
- tagCriteria . SetProjection ( Projections . Property ( "t.Name" ) ) ;
116
+ var projectNameProjection = Projections . SubQuery ( projectCriteria ) ;
111
117
112
- // run query
118
+ tagCriteria . Add ( Restrictions . Eq ( projectNameProjection , "Beta" ) ) ;
119
+ tagCriteria . SetProjection ( Projections . Property ( "t.Name" ) ) ;
113
120
114
- var results = await ( tagCriteria . ListAsync ( ) ) ;
121
+ // run query
122
+ var results = await ( tagCriteria . ListAsync ( ) ) ;
115
123
116
- Assert . That ( results , Is . EquivalentTo ( new [ ] { "B17" } ) ) ;
117
- }
124
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { "B17" } ) ) ;
118
125
}
119
126
}
120
127
}
0 commit comments