You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -52,34 +54,41 @@ public async Task WithClauseFailsWithFetchAsync()
52
54
}
53
55
54
56
[Test]
55
-
publicasyncTaskInvalidWithSemanticsAsync()
57
+
publicasyncTaskValidWithSemanticsAsync()
56
58
{
57
-
ISessions=OpenSession();
58
-
ITransactiontxn=s.BeginTransaction();
59
-
60
-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
61
-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
62
-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
63
-
// joins relating to the sublcass/superclass tables
64
-
Assert.ThrowsAsync<InvalidWithClauseException>(
65
-
()=>
66
-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit",1).
67
-
ListAsync());
68
-
69
-
Assert.ThrowsAsync<InvalidWithClauseException>(
70
-
()=>
71
-
s.CreateQuery(
72
-
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").
73
-
ListAsync());
74
-
75
-
Assert.ThrowsAsync<InvalidWithClauseException>(
76
-
async()=>
77
-
await(s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin").SetEntity("cousin",
78
-
await(s.LoadAsync<Human>(123L)))
79
-
.ListAsync()));
59
+
using(vars=OpenSession())
60
+
{
61
+
await(s.CreateQuery(
62
+
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").ListAsync());
63
+
}
64
+
}
80
65
81
-
await(txn.CommitAsync());
82
-
s.Close();
66
+
[Test]
67
+
publicasyncTaskInvalidWithSemanticsAsync()
68
+
{
69
+
using(ISessions=OpenSession())
70
+
{
71
+
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
72
+
// alias relates to the Human.friends collection which the aonther Human entity. The issue
73
+
// here is the way JoinSequence and Joinable (the persister) interact to generate the
74
+
// joins relating to the sublcass/superclass tables
75
+
Assert.ThrowsAsync<InvalidWithClauseException>(
76
+
()=>
77
+
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit",1).ListAsync());
78
+
79
+
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
80
+
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
81
+
try
82
+
{
83
+
await(s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
84
+
.SetInt32("cousin",123)
85
+
.ListAsync());
86
+
}
87
+
catch(GenericADOException)
88
+
{
89
+
//Apparently SQLite can process queries with wrong join orders
90
+
}
91
+
}
83
92
}
84
93
85
94
[Test]
@@ -175,4 +184,4 @@ public TestData(WithClauseFixtureAsync tc)
Copy file name to clipboardExpand all lines: src/NHibernate.Test/Hql/Ast/WithClauseFixture.cs
+35-26Lines changed: 35 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
+
usingSystem;
1
2
usingSystem.Collections;
3
+
usingNHibernate.Exceptions;
2
4
usingNHibernate.Hql.Ast.ANTLR;
3
5
usingNUnit.Framework;
4
6
@@ -40,34 +42,41 @@ public void WithClauseFailsWithFetch()
40
42
}
41
43
42
44
[Test]
43
-
publicvoidInvalidWithSemantics()
45
+
publicvoidValidWithSemantics()
44
46
{
45
-
ISessions=OpenSession();
46
-
ITransactiontxn=s.BeginTransaction();
47
-
48
-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
49
-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
50
-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
51
-
// joins relating to the sublcass/superclass tables
52
-
Assert.Throws<InvalidWithClauseException>(
53
-
()=>
54
-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit",1).
55
-
List());
56
-
57
-
Assert.Throws<InvalidWithClauseException>(
58
-
()=>
47
+
using(vars=OpenSession())
48
+
{
59
49
s.CreateQuery(
60
-
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").
61
-
List());
62
-
63
-
Assert.Throws<InvalidWithClauseException>(
64
-
()=>
65
-
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin").SetEntity("cousin",
66
-
s.Load<Human>(123L))
67
-
.List());
50
+
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").List();
51
+
}
52
+
}
68
53
69
-
txn.Commit();
70
-
s.Close();
54
+
[Test]
55
+
publicvoidInvalidWithSemantics()
56
+
{
57
+
using(ISessions=OpenSession())
58
+
{
59
+
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
60
+
// alias relates to the Human.friends collection which the aonther Human entity. The issue
61
+
// here is the way JoinSequence and Joinable (the persister) interact to generate the
62
+
// joins relating to the sublcass/superclass tables
63
+
Assert.Throws<InvalidWithClauseException>(
64
+
()=>
65
+
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit",1).List());
66
+
67
+
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
68
+
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
69
+
try
70
+
{
71
+
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
72
+
.SetInt32("cousin",123)
73
+
.List();
74
+
}
75
+
catch(GenericADOException)
76
+
{
77
+
//Apparently SQLite can process queries with wrong join orders
0 commit comments