I use Entity Framework 7 with Npgsql adapter. Sql generated by EF seems like
SELECT "r"."Id", "r"."Name" FROM "public"."Role" AS "r"
and it doesn't work in Postgres, because case-sensitive policy. To make it work i need to write create table script
CREATE TABLE "Role" (
"Id" int,
"Name" varchar(200)
);
But it's ugly. Is there the way to make EF generate scripts without quotes or with lowercase naming style?
Override DelimitIdentifier in NpgsqlSqlGenerationHelper like this:
public class SqlGenerationHelper : NpgsqlSqlGenerationHelper
{
public override string DelimitIdentifier(string identifier) => identifier.Contains(".") ? base.DelimitIdentifier(identifier) : identifier;
}
Replace ISqlGenerationHelper with your class using ReplaceService method:
public class MyContext : DbContext
{
public virtual DbSet<MyTable> MyTable { get; set; }
public MyContext(DbConnection connection) :
base(new DbContextOptionsBuilder().UseNpgsql(connection)
.ReplaceService<ISqlGenerationHelper, SqlGenerationHelper>()
.Options)
{ }
}