Entity Framework 7中表和属性的大小写不敏感名称 [英] Case insensitive name of tables and properties in Entity Framework 7
问题描述
我将Entity Framework 7与Npgsql适配器一起使用。 EF生成的SQL似乎是
I use Entity Framework 7 with Npgsql adapter. Sql generated by EF seems like
SELECT "r"."Id", "r"."Name" FROM "public"."Role" AS "r"
,并且在Postgres中不起作用,因为区分大小写政策。要使其正常工作,我需要编写创建表脚本
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)
);
但这很丑。有没有办法使EF生成不带引号或具有小写命名风格的脚本?
But it's ugly. Is there the way to make EF generate scripts without quotes or with lowercase naming style?
推荐答案
Npgsql生成引号有一个很好的理由到处都是-因此您绝对不应删除它们(即使在技术上也可以按照@natemcmaster所说)。不带引号的标识符由PostgreSQL自动转换为小写。实体框架需要能够将C#属性映射到数据库列,但是C#属性区分大小写。因此,如果您删除数据库的区分大小写功能,那您就开枪了...
There's a very good reason Npgsql generates quotes everywhere - so you definitely should not remove them (even if it's technically possible as @natemcmaster says). Identifiers without quotes are automatically converted to lowercase by PostgreSQL. Entity Framework needs to be able to map C# properties to database columns, but C# properties are case-sensitive; so if you remove database case sensitivity you're shooting yourself in the foot...
除非您有真正的问题(除了感知到的丑陋之外),否则您应该离开照原样。
Unless you have a real problem (aside from the perceived ugliness) you should leave things as they are.
这篇关于Entity Framework 7中表和属性的大小写不敏感名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!