EFCore.BulkExtensions与PostgreSQL提供程序生成的表和列名均为大写字母。

huangapple go评论48阅读模式
英文:

EFCore.BulkExtensions with postgresql provider generates table and column names in capital letters

问题

I can provide the translation for the non-code parts:

我使用 Microsoft.EntityFrameworkCore 6.0 和 Npgsql.EntityFrameworkCore.PostgreSQL 6.0。
我有一个这样配置的 dbContext:
我在上下文中有一个绑定的属性,我使用 .BatchDelete()
问题是,我在控制台中记录了一个错误 Npgsql.PostgresException (0x80004005): 42P01: relation "TEMPORARYS" does not exist
生成的 SQL 如下:
问题是,表名和列名配置为小写。
有人可以帮助我吗,我该如何让它正常工作而不转换表和列名?
还是我需要在 PostgreSQL 中进行特殊配置?
最好的问候,Julian

英文:

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

答案1

得分: 0

根据Shay Rojansky在评论部分建议,升级到EF Core 7.0就可以解决问题。

英文:

As Shay Rojansky suggested in the comment section, upgrading to EF Core 7.0 does the trick

huangapple
  • 本文由 发表于 2023年4月6日 19:55:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定