Skip to content

Commit 03fab1f

Browse files
authored
Preserve original table name casing for aliases (#947)
Stop lowercasing table aliases in DescriptiveSqlAliasManager and use the original table name as the alias key and return value. Update verified SQL test snapshots to reflect PascalCase table aliases (Companies/Employees). Also replace a recursive GetNavigations call with a direct model.GetNavigations() invocation and add a trailing newline at EOF.
1 parent 0427dbd commit 03fab1f

5 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;CS8632;EF1001;NU1608;NU1109</NoWarn>
5-
<Version>15.0.0</Version>
5+
<Version>15.0.1</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<PackageTags>EntityFramework, Verify</PackageTags>

src/Verify.EntityFramework.Tests/CoreTests.DescriptiveTableAliases.verified.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
Type: ReaderExecutedAsync,
44
HasTransaction: false,
55
Text:
6-
select companies.Id,
7-
companies.Name,
8-
employees.Id,
9-
employees.Age,
10-
employees.CompanyId,
11-
employees.Name
12-
from Companies as companies
6+
select Companies.Id,
7+
Companies.Name,
8+
Employees.Id,
9+
Employees.Age,
10+
Employees.CompanyId,
11+
Employees.Name
12+
from Companies as Companies
1313
left outer join
14-
Employees as employees
15-
on companies.Id = employees.CompanyId
16-
order by companies.Name,
17-
companies.Id
14+
Employees as Employees
15+
on Companies.Id = Employees.CompanyId
16+
order by Companies.Name,
17+
Companies.Id
1818
}
1919
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
select companies.Id,
2-
companies.Name
3-
from Companies as companies
4-
where companies.Name = N'company name'
1+
select Companies.Id,
2+
Companies.Name
3+
from Companies as Companies
4+
where Companies.Name = N'company name'

src/Verify.EntityFramework/DescriptiveSqlAliasManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ class DescriptiveSqlAliasManager : SqlAliasManager
66

77
public override string GenerateTableAlias(string name)
88
{
9-
var lowerName = name.ToLowerInvariant();
10-
11-
if (aliases.TryGetValue(lowerName, out var counter))
9+
if (aliases.TryGetValue(name, out var counter))
1210
{
13-
aliases[lowerName] = counter + 1;
14-
return lowerName + counter;
11+
aliases[name] = counter + 1;
12+
return name + counter;
1513
}
1614

17-
aliases[lowerName] = 0;
18-
return lowerName;
15+
aliases[name] = 0;
16+
return name;
1917
}
2018

2119
protected override Dictionary<string, string>? RemapTableAliases(IReadOnlySet<string> usedAliases) =>

src/Verify.EntityFramework/VerifyEntityFramework.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void IgnoreNavigationProperties(IModel? model = null)
8686
throw new("The `model` parameter must be provided wither on this method or on VerifyEntityFramework.Enable()");
8787
}
8888

89-
return GetNavigations(model);
89+
return model.GetNavigations();
9090
}
9191

9292
static IEnumerable<(Type type, string name)> GetNavigations(this IModel model)
@@ -190,4 +190,4 @@ public static void DisableRecording<TContext>(this TContext context)
190190
internal static bool IsRecordingDisabled<TContext>(this TContext context)
191191
where TContext : DbContext =>
192192
recordingDisabledContextIds.Contains(context.ContextId.InstanceId);
193-
}
193+
}

0 commit comments

Comments
 (0)