Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capitalize database name #27966

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public virtual string GetPrincipalEndCandidateNavigationPropertyName(
: foreignKey.DeclaringEntityType.ShortName();
}

private static string GenerateCandidateIdentifier(string originalIdentifier)
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string GenerateCandidateIdentifier(string originalIdentifier)
{
var candidateStringBuilder = new StringBuilder();
var previousLetterCharInWordIsLowerCase = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public interface ICandidateNamingService
/// </summary>
string GenerateCandidateIdentifier(DatabaseColumn originalColumn);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
string GenerateCandidateIdentifier(string databaseName);


/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ protected virtual ModelBuilder VisitDatabaseModel(ModelBuilder modelBuilder, Dat

if (!string.IsNullOrEmpty(databaseModel.DatabaseName))
{
modelBuilder.Model.SetDatabaseName(databaseModel.DatabaseName);
modelBuilder.Model.SetDatabaseName(
_options.UseDatabaseNames && !string.IsNullOrEmpty(databaseModel.DatabaseName)
ilmalte marked this conversation as resolved.
Show resolved Hide resolved
? _candidateNamingService.GenerateCandidateIdentifier(databaseModel.DatabaseName)
: databaseModel.DatabaseName);
}

if (!string.IsNullOrEmpty(databaseModel.Collation))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public RelationalScaffoldingModelFactoryTest()
_reporter.Clear();
}

[ConditionalFact]
public void Capitalize_DatabaseName()
{
var database = new DatabaseModel { DatabaseName = "northwind" };
var model = _factory.Create(database, new ModelReverseEngineerOptions { UseDatabaseNames = true });
ilmalte marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal("Northwind", model.GetDatabaseName());
}

[ConditionalFact]
public void Creates_entity_types()
{
Expand Down Expand Up @@ -131,6 +139,27 @@ public void Creates_entity_types_case_insensitive()
Assert.Equal(2, model.GetEntityTypes().Select(et => et.Name).Distinct(StringComparer.OrdinalIgnoreCase).Count());
}

[ConditionalTheory]
[InlineData("PascalCase")]
[InlineData("camelCase")]
[InlineData("snake-case")]
[InlineData("MixedCASE")]
[InlineData("separated_by_underscores")]
[InlineData("PascalCase_withUnderscore")]
[InlineData("ALL_CAPS")]
[InlineData("numbers0Dont1Affect23Upper45Case678To9LowerCase10Boundary999")]
[InlineData("We1!*~&%rdCh@r^act()0rs")]
public void Get_DatabaseName(string expectedValue)
{
var options = new ModelReverseEngineerOptions { UseDatabaseNames = false };

var database = new DatabaseModel { DatabaseName = expectedValue };
var model = _factory.Create(database, options);
Assert.Equal(expectedValue, model.GetDatabaseName());

}


[ConditionalFact]
public void Loads_column_types()
{
Expand Down