Entity Framework 7 中的表和属性的名称不区分大小写 [英] Case insensitive name of tables and properties in Entity Framework 7

查看:20
本文介绍了Entity Framework 7 中的表和属性的名称不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有 Npgsql 适配器的 Entity Framework 7.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 自动转换为小写.Entity Framework 需要能够将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆