I'm using Microsoft.EntityFrameworkCore
6.0 and Npgsql.EntityFrameworkCore.PostgreSQL
6.0.
I have a dbContext that is configured like this:
var dbContextOptions = new DbContextOptionsBuilder<DataProtectionDbContext>();
dbContextOptions.UseNpgsql(config.GetConnectionString("DataProtection"), x => x.MigrationsHistoryTable(Constants.EFCoreMigrationsHistoryTableName))
.UseSnakeCaseNamingConvention();
I have a bound property in the context that I use .BatchDelete()
on.
var query = dataProtectionDbContext.Temporarys.Where(m => m.CreatedTime < DateTime.UtcNow.AddDays(-temporarys_MaxAgeInDays));
query.BatchDelete();
The problem is, that I got an error logged in the console Npgsql.PostgresException (0x80004005): 42P01: relation "TEMPORARYS" does not exist
The generated sql is:
DELETE
FROM "TEMPORARYS" AS t
WHERE t."CREATED_TIME" < (now() + CAST((@__p_0::text || ' days') AS interval))
The problem is, that the table name and the column name are configured to be in lowercase:
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);
});
Can someone help me, how can I do this to work and not convert the table and column names? Or is there some special configuration that I have to make in order this to work with PostgreSQL?
Best Regards,
Julian
As Shay Rojansky suggested in the comment section, upgrading to EF Core 7.0 does the trick