diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs index a5e17e87daf..fc7b2dee089 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs @@ -230,6 +230,7 @@ ORDER BY "cid" _logger.ColumnFound(table.Name, columnName, dataType, notNull, defaultValue); + string? collation = null; var autoIncrement = 0; if (connection is SqliteConnection sqliteConnection && !(table is DatabaseView)) @@ -241,7 +242,7 @@ ORDER BY "cid" table.Name, columnName, out _, - out _, + out collation, out _, out _, out autoIncrement); @@ -264,7 +265,10 @@ ORDER BY "cid" : string.Empty, IsStored = hidden != 3L ? default(bool?) - : true + : true, + Collation = string.Equals(collation, "BINARY", StringComparison.OrdinalIgnoreCase) + ? null + : collation }); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs index aadc0e8d23e..c9c96b02a8a 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs @@ -471,6 +471,26 @@ CREATE TABLE AutoIncTest ( }, "DROP TABLE AutoIncTest"); + [ConditionalFact] + public void Column_collation_is_set() + => Test( + @" +CREATE TABLE ColumnsWithCollation ( + Id int, + DefaultCollation text, + NonDefaultCollation text COLLATE NOCASE +);", + Enumerable.Empty(), + Enumerable.Empty(), + dbModel => + { + var columns = dbModel.Tables.Single().Columns; + + Assert.Null(columns.Single(c => c.Name == "DefaultCollation").Collation); + Assert.Equal("NOCASE", columns.Single(c => c.Name == "NonDefaultCollation").Collation); + }, + "DROP TABLE ColumnsWithCollation;"); + #endregion #region PrimaryKeyFacets