|
8 | 8 | //------------------------------------------------------------------------------
|
9 | 9 |
|
10 | 10 |
|
11 |
| -using System; |
12 | 11 | using System.Collections;
|
13 |
| -using NHibernate.Exceptions; |
14 | 12 | using NHibernate.Hql.Ast.ANTLR;
|
15 | 13 | using NUnit.Framework;
|
16 | 14 |
|
@@ -54,40 +52,21 @@ public async Task WithClauseFailsWithFetchAsync()
|
54 | 52 | }
|
55 | 53 |
|
56 | 54 | [Test]
|
57 |
| - public async Task ValidWithSemanticsAsync() |
| 55 | + public async Task WithClauseOnSubclassesAsync() |
58 | 56 | {
|
59 | 57 | using (var s = OpenSession())
|
60 | 58 | {
|
61 | 59 | await (s.CreateQuery(
|
62 | 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").ListAsync());
|
63 |
| - } |
64 |
| - } |
65 | 61 |
|
66 |
| - [Test] |
67 |
| - public async Task InvalidWithSemanticsAsync() |
68 |
| - { |
69 |
| - using (ISession s = 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 |
| - } |
| 62 | + // f.bodyWeight is a reference to a column on the Animal table; however, the 'f' |
| 63 | + // alias relates to the Human.friends collection which the aonther Human entity. |
| 64 | + // Group join allows us to use such constructs |
| 65 | + await (s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).ListAsync()); |
| 66 | + |
| 67 | + await (s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin") |
| 68 | + .SetInt32("cousin", 123) |
| 69 | + .ListAsync()); |
91 | 70 | }
|
92 | 71 | }
|
93 | 72 |
|
|
0 commit comments