|
2 | 2 | using System.Linq;
|
3 | 3 | using NHibernate.Engine;
|
4 | 4 | using NHibernate.Hql.Ast.ANTLR.Tree;
|
| 5 | +using NHibernate.Util; |
5 | 6 |
|
6 | 7 | namespace NHibernate.Hql.Ast.ANTLR
|
7 | 8 | {
|
@@ -30,30 +31,25 @@ private IASTNode[] Process()
|
30 | 31 | _nodeMapping = new PolymorphicQuerySourceDetector(_factory).Process(_ast);
|
31 | 32 |
|
32 | 33 | if (_nodeMapping.Count > 0)
|
33 |
| - { |
34 |
| - foreach (var kv in _nodeMapping.Where(x => x.Value.Length == 0)) |
35 |
| - throw new QuerySyntaxException(kv.Key + " is not mapped"); |
36 |
| - |
37 |
| - return DuplicateTree().ToArray(); |
| 34 | + { |
| 35 | + if (_nodeMapping.All(x => x.Value.Length == 0)) |
| 36 | + throw new QuerySyntaxException( |
| 37 | + _nodeMapping.Keys.Count == 1 |
| 38 | + ? _nodeMapping.First().Key + " is not mapped" |
| 39 | + : string.Join(", ", _nodeMapping.Keys) + " are not mapped"); |
| 40 | + |
| 41 | + return DuplicateTree(); |
38 | 42 | }
|
39 | 43 | else
|
40 | 44 | {
|
41 | 45 | return new[] { _ast };
|
42 | 46 | }
|
43 | 47 | }
|
44 | 48 |
|
45 |
| - private IEnumerable<IASTNode> DuplicateTree() |
| 49 | + private IASTNode[] DuplicateTree() |
46 | 50 | {
|
47 | 51 | var replacements = CrossJoinDictionaryArrays.PerformCrossJoin(_nodeMapping);
|
48 |
| - |
49 |
| - var dups = new IASTNode[replacements.Count()]; |
50 |
| - |
51 |
| - for (var i = 0; i < replacements.Count(); i++) |
52 |
| - { |
53 |
| - dups[i] = DuplicateTree(_ast, replacements[i]); |
54 |
| - } |
55 |
| - |
56 |
| - return dups; |
| 52 | + return replacements.ToArray(x => DuplicateTree(_ast, x)); |
57 | 53 | }
|
58 | 54 |
|
59 | 55 | private static IASTNode DuplicateTree(IASTNode ast, IDictionary<IASTNode, IASTNode> nodeMapping)
|
|
0 commit comments