Case insensitive name of tables and properties in Entity Framework 7

前端 未结 6 1875
萌比男神i
萌比男神i 2021-01-03 00:26

I use Entity Framework 7 with Npgsql adapter. Sql generated by EF seems like

SELECT \"r\".\"Id\", \"r\".\"Name\" FROM \"public\".\"Role\" AS \"r\"

6条回答
  •  天命终不由人
    2021-01-03 01:10

    As you can see in NpgsqlSqlGenerationHelper.cs:

    static bool RequiresQuoting(string identifier)
    {
            var first = identifier[0];
            if (!char.IsLower(first) && first != '_')
                return true;
    

    Npgsql thinks that identifiers that start with upper-case letter needs quoting. After a bit of thinking I implemented a solution described in https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/ (converts all PascalCase identifiers to snake-case). It is a bit simplistic right now but I how EF Core soon will provide a way to define custom naming conventions.

提交回复
热议问题