-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathOracleQueryCompilationContext.cs
More file actions
69 lines (55 loc) · 2.13 KB
/
OracleQueryCompilationContext.cs
File metadata and controls
69 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
using System;
using System.Collections.Generic;
namespace Microsoft.EntityFrameworkCore.Oracle.Query.Internal
{
public class OracleQueryCompilationContext : RelationalQueryCompilationContext
{
private readonly ISet<string> _tableAliasSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
public OracleQueryCompilationContext(
[NotNull] QueryCompilationContextDependencies dependencies,
[NotNull] ILinqOperatorProvider linqOperatorProvider,
[NotNull] IQueryMethodProvider queryMethodProvider,
bool trackQueryResults)
: base(
dependencies,
linqOperatorProvider,
queryMethodProvider,
trackQueryResults)
{
}
public override bool IsLateralJoinSupported => true;
public override int MaxTableAliasLength => 5;
private string GetRandomLetter(Random rng)
{
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int index = rng.Next(letters.Length);
return letters[index].ToString();
}
private string GetUniqueTableAlias()
{
var rdm = new Random();
return GetRandomLetter(rdm) + rdm.Next(0, 10);
}
public override string CreateUniqueTableAlias([NotNull] string currentAlias)
{
Check.NotNull(currentAlias, nameof(currentAlias));
if (currentAlias.Length == 0)
{
return currentAlias;
}
var uniqueAlias = GetUniqueTableAlias();
while (_tableAliasSet.Contains(uniqueAlias))
{
uniqueAlias = GetUniqueTableAlias();
}
_tableAliasSet.Add(uniqueAlias);
return uniqueAlias;
}
}
}