我使用Microsoft.EntityFrameworkCore
6.0和Npgsql.EntityFrameworkCore.PostgreSQL
6.0。我有一个这样配置的dbContext:
var dbContextOptions = new DbContextOptionsBuilder<DataProtectionDbContext>();
dbContextOptions.UseNpgsql(config.GetConnectionString("DataProtection"), x => x.MigrationsHistoryTable(Constants.EFCoreMigrationsHistoryTableName))
.UseSnakeCaseNamingConvention();
在我使用.BatchDelete()
的上下文中我有一个绑定属性
var query = dataProtectionDbContext.Temporarys.Where(m => m.CreatedTime < DateTime.UtcNow.AddDays(-temporarys_MaxAgeInDays));
query.BatchDelete();
问题是,我在控制台Npgsql.PostgresException (0x80004005): 42P01: relation "TEMPORARYS" does not exist
中记录了一个错误生成的sql是:
DELETE
FROM "TEMPORARYS" AS t
WHERE t."CREATED_TIME" < (now() + CAST((@__p_0::text || ' days') AS interval))
问题是,表名和列名配置为小写:
migrationBuilder.CreateTable(
name: "temporarys",
columns: table => new
{
id = table.Column<Guid>(nullable: false),
created_time = table.Column<DateTime>(nullable: false),
tenant_id = table.Column<string>(maxLength: 50, nullable: true),
key = table.Column<string>(maxLength: 50, nullable: true),
value = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Temporarys", x => x.id);
});
有人能帮助我,我怎么能做到这一点的工作,而不是转换表和列名?或者有一些特殊的配置,我必须做出,以便与PostgreSQL工作?
最诚挚的问候,朱利安
正如Shay Rojansky在评论部分建议的那样,升级到EF Core 7.0可以解决这个问题