项目使用运行。Net Core 2.2、EF Core和SQL Server。现在,我需要将这个项目与Oracle11g一起使用。我用Oracle创建了一个新的迁移项目。ManagedDataAccess。果心生成的迁移文件如下:
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);
});
生成的脚本是:
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;
但是,在Oracle 11g中不存在IDENTITY命令。PKs必须使用触发器和序列生成。
如何配置de EF Core以生成Oracle 11g版本的命令?
来自https://docs.oracle.com/en/database/oracle/oracle-data-access-components/19.3/odpnt/EFCoreAPI.html#GUID-770CD8EA-F963-48A5-A679-CAF471A4DB1A
使用Oracle数据库11.2版的客户应设置
UseOracleSQLCompatibility("11")
optionsBuilder.UseOracle("User Id=hr;Password=<password>;Data Source = inst1", b =>
b.UseOracleSQLCompatibility("11"));