Creating table on Oracle Db by Entity Framework 6 effect table name string format
Creating table on Oracle Db by Entity Framework 6 effect table name string format
我不确定这个问题的标题是什么,但我遇到了奇怪的问题。我通过使用提供程序 Oracle.ManagedDataAccess 在 Oracle DB 12c 上使用 EF 6 和代码优先方法。我的实体 类 是通过它们在 Db 上的默认名称创建的。例如,User
=> Users
、Role
=> Roles
。当我尝试在 PL/SQL 开发者工具上查询 table 时,例如
select * from Users t
会出现类似
的错误
ORA-00942: table or view does not exist
连table都满了。意思是"there is no table or view"。在尝试了很多方法之后,我发现如果我像
这样查询
select * from "Users" t
我现在可以访问数据了。所以问题是 "why does it happen?", "what effects this?"
这是Oracle命名规则造成的。 SQL 是不区分大小写的语言,所以当你写
select * from Users
Oracle 将此理解为
select * from USERS
但与此同时,Oracle 允许您创建具有不寻常名称的 table,这些名称必须包含在引号内。要查询这个 table 你需要像在 create table
语句中那样写它的名字。这是 SQL*Plus:
的脚本
SQL> create table "My Table with WEIRD Name" (id number);
Table created.
SQL> select * from "My Table with WEIRD Name";
no rows selected
这样的名字是区分大小写的,而且,正如我猜测的那样,Entity Framework 创建了这样的名字。名称 USERS
和 "USERS"
是等效的,名称 USERS
和 "Users"
- 不是。这就是为什么您的查询作为
select * from "Users"
更多信息在 documentation。
我不确定这个问题的标题是什么,但我遇到了奇怪的问题。我通过使用提供程序 Oracle.ManagedDataAccess 在 Oracle DB 12c 上使用 EF 6 和代码优先方法。我的实体 类 是通过它们在 Db 上的默认名称创建的。例如,User
=> Users
、Role
=> Roles
。当我尝试在 PL/SQL 开发者工具上查询 table 时,例如
select * from Users t
会出现类似
的错误ORA-00942: table or view does not exist
连table都满了。意思是"there is no table or view"。在尝试了很多方法之后,我发现如果我像
这样查询select * from "Users" t
我现在可以访问数据了。所以问题是 "why does it happen?", "what effects this?"
这是Oracle命名规则造成的。 SQL 是不区分大小写的语言,所以当你写
select * from Users
Oracle 将此理解为
select * from USERS
但与此同时,Oracle 允许您创建具有不寻常名称的 table,这些名称必须包含在引号内。要查询这个 table 你需要像在 create table
语句中那样写它的名字。这是 SQL*Plus:
SQL> create table "My Table with WEIRD Name" (id number);
Table created.
SQL> select * from "My Table with WEIRD Name";
no rows selected
这样的名字是区分大小写的,而且,正如我猜测的那样,Entity Framework 创建了这样的名字。名称 USERS
和 "USERS"
是等效的,名称 USERS
和 "Users"
- 不是。这就是为什么您的查询作为
select * from "Users"
更多信息在 documentation。