Skip to content

Commit

Permalink
Fix collation scaffolding
Browse files Browse the repository at this point in the history
Fixes #23386
  • Loading branch information
roji committed Nov 19, 2020
1 parent 44fb095 commit c1b0443
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ protected virtual ModelBuilder VisitDatabaseModel([NotNull] ModelBuilder modelBu
modelBuilder.Model.SetDatabaseName(databaseModel.DatabaseName);
}

if (!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 +502,7 @@ protected virtual PropertyBuilder VisitColumn([NotNull] EntityTypeBuilder builde

if (column.Collation != null)
{
property.HasComment(column.Collation);
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

0 comments on commit c1b0443

Please sign in to comment.