简体   繁体   English

PostgreSQL:42883:运算符不存在:information_schema.sql_identifier + 未知

[英]PostgreSQL: 42883: operator does not exist: information_schema.sql_identifier + unknown

.NET Core 2.2 application with Npgsql EF Core 2.2.4, Npgsql Nodatime 2.2.4 .NET Core 2.2 应用程序与 Npgsql EF Core 2.2.4、Npgsql Nodatime 2.2.4

I'm trying to bulk update records and Entity Framework is throwing an exception 42883: operator does not exist: information_schema.sql_identifier + unknown我正在尝试批量更新记录,实体框架抛出异常42883: operator does not exist: information_schema.sql_identifier + unknown

If I don't use BulkUpdate and instead use如果我不使用 BulkUpdate 而是使用

_dbContext.UpdateRange(data)
_dbContext.SaveChanges();

then everything is fine.那么一切都很好。 But I was wondering why it is not working with _dbContext.BulkUpdate(data) ?但我想知道为什么它不能与_dbContext.BulkUpdate(data)

The following is a sanitized version of what we're doing:以下是我们正在做的事情的净化版本:

public void BulkUpdate(List<AutoAction> data)
{
    try
    {
        _dbContext.BulkUpdate(data);
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        throw;
    }
}

public class AutoAction
{
    public int Id { get; set; }
    public int SettingsId { get; set; }
    public Settings Setting { get; set; }
    public Type ActionType { get; set; }
    public LocalDate DateEffective { get; set; }
    public bool Processed { get; set; }
    public Instant CreatedDateUtc { get; set; }
    public Instant? ProcessedOnUtc { get; set; }
    public Status Status { get; set; }
}

DbContext.cs数据库上下文

public DbSet<AutoAction> AutoActions { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.ApplyConfiguration(new AutoActionConfiguration());
    base.OnModelCreating(modelBuilder);
}

AutoActionConfiguration.cs自动操作配置.cs

public class AutoActionConfiguration : IEntityTypeConfiguration<AutoAction> 
{
    public void Configure(EntityTypeBuilder<AutoAction> builder)
    {
        builder.ToTable("AutoAction");
        builder.HasKey(x => x.Id);
        builder.Ignore(x => x.Setting);
        builder.Property(x => x.Id).ValueGeneratedOnAdd();
        builder.Property(a => a.Processed).HasColumnType("BOOLEAN");
        builder.Property(a => a.ProcessedOnUtc).HasColumnType("timestamp");
        builder.Property(a => a.CreatedDateUtc).HasColumnType("timestamp");
        builder.Property(a => a.DateEffective).HasColumnType("date");

        var actionTypeConverter = new EnumToNumberConverter<Type, int>();
        builder.Property(a => a.ActionType).HasConversion(actionTypeConverter).HasColumnName("ActionType");

        var statusTypeConverter = new EnumToNumberConverter<Status, int>();
        builder.Property(a => a.Status).HasConversion(statusTypeConverter).HasColumnName("Status");
    }
}

Startup.cs启动文件

services.AddDbContext<DbContext>((serviceProvider, options) =>
            {
                var factory = serviceProvider.GetRequiredService<IConnectionFactory>();

                var connection = factory.GetPostgresServerConnection();

                options.UseNpgsql(connection, optionsBuilder =>
                {
                    var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;

                    var extension = coreOptionsBuilder.Options.FindExtension<NpgsqlNodaTimeOptionsExtension>()
                                    ?? new NpgsqlNodaTimeOptionsExtension();

                    ((IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder).AddOrUpdateExtension(extension);
                });
            });

Exception例外

hint: No operator matches the given name and argument types. You might need to add explicit type casts.

stacktrace: at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 446
   at Npgsql.NpgsqlDataReader.NextResult() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 332
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1218
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1130
   at EFCore.BulkExtensions.TableInfo.CheckHasIdentity(DbContext context)
   at EFCore.BulkExtensions.SqlBulkOperation.Merge[T](DbContext context, IList`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkExtensions.BulkUpdate[T](DbContext context, IList`1 entities, BulkConfig bulkConfig, Action`1 progress)

SQL: SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 and TABLE_NAME = 'autoaction' and TABLE_SCHEMA = 'dbo'
   42883: operator does not exist: information_schema.sql_identifier + unknown

Not sure where to add explicit type casts as it is mentioned as a hint from the exception.不确定在哪里添加显式类型转换,因为它被作为异常提示提到。

The way I ready that error it is trying to find a column with IDENTITY property in the table rateautoaction and can't.我准备该错误的方式是尝试在表 rateautoaction 中找到具有 IDENTITY 属性的列,但无法找到。

It seems like this is a requirement for using this function.似乎这是使用此功能的要求。

The other part I don't understand is the SQL there shows the function COLUMNPROPERTY being called -- but that is only on SQL Server.我不明白的另一部分是那里的 SQL 显示函数 COLUMNPROPERTY 被调用——但这仅在 SQL Server 上。 But you say you are using PostgreSQL.但是你说你使用的是PostgreSQL。

Are you using SQL Server library with Postgre?您是否在 Postgre 中使用 SQL Server 库? That would not be a good idea.那可不是个好主意。

暂无
暂无

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

相关问题 PostgreSQL:42883 运算符不存在:没有时区的时间戳 = 文本 - PostgreSQL: 42883 Operator does not exist: timestamp without time zone = text PostgreSQL:42883运算符不存在:没有时区的时间戳 - PostgreSQL: 42883 Operator does not exist: timestamp without time zone PostgresException:42883:运算符不存在:@字符变化 - PostgresException: 42883: operator does not exist: @ character varying Npgsql.PostgresException (0x80004005): 42883: 运算符不存在: jsonb #&gt; text - Npgsql.PostgresException (0x80004005): 42883: operator does not exist: jsonb #> text 从 C# 调用时,Npgsql.Postgresql 异常 42883 function 不存在 - 是否有可用的工作示例? - Npgsql.Postgresql Exception 42883 function does not exist when called from C# - is there a working example available? 42883:函数不存在-在Entity Framework C#Npgsql中调用Postgres函数 - 42883: function does not exist - Calling Postgres Functions in Entity Framework C# Npgsql PostgresException:42883:尝试调用过程时,函数X(没有时区的时间戳)不存在 - PostgresException: 42883: function X(timestamp without time zone) does not exist when trying to call procedure PostgreSQL“列“ foo”不存在” - PostgreSQL “Column ”foo“ does not exist” 错误名称“标识符”在当前上下文中不存在 - Error The name 'Identifier' does not exist in the current context 运算符不存在:@timestamp without time zone - operator does not exist: @ timestamp without time zone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM