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

[5.0.1] Fix collation scaffolding #23414

Merged
merged 2 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -29,6 +29,9 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// </summary>
public class RelationalScaffoldingModelFactory : IScaffoldingModelFactory
{
private static readonly bool _useOldBehavior
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23386", out var enabled) && enabled;

internal const string NavigationNameUniquifyingPattern = "{0}Navigation";
internal const string SelfReferencingPrincipalEndNavigationNamePattern = "Inverse{0}";

Expand Down Expand Up @@ -194,6 +197,11 @@ protected virtual ModelBuilder VisitDatabaseModel([NotNull] ModelBuilder modelBu
modelBuilder.Model.SetDatabaseName(databaseModel.DatabaseName);
}

if (!_useOldBehavior && !string.IsNullOrEmpty(databaseModel.Collation))
{
modelBuilder.UseCollation(databaseModel.Collation);
}

VisitSequences(modelBuilder, databaseModel.Sequences);
VisitTables(modelBuilder, databaseModel.Tables);
VisitForeignKeys(modelBuilder, databaseModel.Tables.SelectMany(table => table.ForeignKeys).ToList());
Expand Down Expand Up @@ -497,7 +505,14 @@ protected virtual PropertyBuilder VisitColumn([NotNull] EntityTypeBuilder builde

if (column.Collation != null)
{
property.HasComment(column.Collation);
if (_useOldBehavior)
{
property.HasComment(column.Collation);
}
else
{
property.UseCollation(column.Collation);
}
}

if (!(column.Table.PrimaryKey?.Columns.Contains(column) ?? false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,50 @@ public void Column_and_table_comments()
Assert.Equal("An int column", column.GetComment());
}

[ConditionalFact]
public void Database_collation()
{
var database = new DatabaseModel
{
Collation = "SomeDatabaseCollation"
};

var model = _factory.Create(database, new ModelReverseEngineerOptions());
Assert.Equal("SomeDatabaseCollation", model.GetCollation());
}

[ConditionalFact]
public void Column_collation()
{
var database = new DatabaseModel
{
Tables =
{
new DatabaseTable
{
Database = Database,
Name = "Table",
Columns =
{
IdColumn,
new DatabaseColumn
{
Table = Table,
Name = "Column",
StoreType = "int",
Collation = "SomeColumnCollation"
}
}
}
}
};

var model = _factory.Create(database, new ModelReverseEngineerOptions());

var column = model.FindEntityType("Table").GetProperty("Column");
Assert.Equal("SomeColumnCollation", column.GetCollation());
}

[ConditionalTheory]
[InlineData(false, false, false)]
[InlineData(false, false, true)]
Expand Down