简体   繁体   English

带有 Oracle 11g 的 EF 内核。 IDENTITY PK 的问题

[英]EF Core with Oracle 11g. Problem with IDENTITY PK

The project is runnig with.Net Core 2.2, EF Core and SQL Server.该项目使用 .Net Core 2.2、EF Core 和 SQL 服务器运行。 Now, I need to use this same projetc with Oracle 11g.现在,我需要将同一个项目与 Oracle 11g 一起使用。 I create a new Migration project with Oracle.ManagedDataAccess.Core.我使用 Oracle.ManagedDataAccess.Core 创建了一个新的迁移项目。 The migration file generated is below:生成的迁移文件如下:

migrationBuilder.CreateTable(
                name: "AREAATUACAO",
                schema: "SISDETEC",
                columns: table => new
                {
                    ID = table.Column<long>(nullable: false)
                        .Annotation("Oracle:ValueGenerationStrategy", OracleValueGenerationStrategy.IdentityColumn),
                    DATACADASTRO = table.Column<DateTime>(nullable: false),
                    DATAATUALIZACAO = table.Column<DateTime>(nullable: false),
                    NOME = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AREAATUACAO", x => x.ID);
                });

And the script generated is:生成的脚本是:

BEGIN 
EXECUTE IMMEDIATE 'CREATE TABLE 
"SISDETEC"."AREAATUACAO" (
    "ID" NUMBER(19) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL,
    "DATACADASTRO" TIMESTAMP(7) NOT NULL,
    "DATAATUALIZACAO" TIMESTAMP(7) NOT NULL,
    "NOME" NVARCHAR2(2000),
    CONSTRAINT "PK_AREAATUACAO" PRIMARY KEY ("ID")
)';
END;

But, in the Oracle 11g do not exists the IDENTITY command.但是,在 Oracle 11g 中不存在 IDENTITY 命令。 The PKs must be generated with a trigger and a sequence.必须使用触发器和序列生成 PK。

How can I config de EF Core to generate commands for Oracle version 11g?如何配置 EF Core 以生成 Oracle 版本 11g 的命令?

from https://docs.oracle.com/en/database/oracle/oracle-data-access-components/19.3/odpnt/EFCoreAPI.html#GUID-770CD8EA-F963-48A5-A679-CAF471A4DB1A来自https://docs.oracle.com/en/database/oracle/oracle-data-access-components/19.3/odpnt/EFCoreAPI.html#GUID-770CD8EA-F963-CAF411A5-A176

Customers using Oracle Database version 11.2 should set UseOracleSQLCompatibility("11")使用 Oracle 数据库版本 11.2 的客户应设置UseOracleSQLCompatibility("11")

optionsBuilder.UseOracle("User Id=hr;Password=<password>;Data Source = inst1", b =>
  b.UseOracleSQLCompatibility("11"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM