Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

enum doesn't work with npgsql on bulkcopy

See original GitHub issue

when trying to bulk copy a list of entities containing Enum parameters (that are represented by enum in postgres) i’m getting this message. (here for the enum currency)

Npgsql.PostgresException (0x80004005): 42804: column "currency" is of type currency but expression is of type integer
   at void Npgsql.NpgsqlConnector+<>c__DisplayClass160_0+<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
   at void Npgsql.NpgsqlConnector+<>c__DisplayClass160_0+<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
   at async Task<bool> Npgsql.NpgsqlDataReader.NextResult(bool async, bool isConsuming)
   at bool Npgsql.NpgsqlDataReader.NextResult()
   at async ValueTask<NpgsqlDataReader> Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, bool async, CancellationToken cancellationToken)
   at async Task<int> Npgsql.NpgsqlCommand.ExecuteNonQuery(bool async, CancellationToken cancellationToken)
   at int Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at int LinqToDB.Data.DbCommandProcessor.DbCommandProcessorExtensions.ExecuteNonQueryExt(IDbCommand cmd)
   at int LinqToDB.Data.DataConnection.ExecuteNonQuery(IDbCommand command)
   at int LinqToDB.Data.DataConnection.ExecuteNonQuery()
   at int LinqToDB.Data.CommandInfo.Execute()
   at int LinqToDB.Data.DataConnectionExtensions.Execute(DataConnection connection, string sql, DataParameter[] parameters)
   at bool LinqToDB.DataProvider.MultipleRowsHelper.Execute()
   at BulkCopyRowsCopied LinqToDB.DataProvider.BasicBulkCopy.MultipleRowsCopy1(MultipleRowsHelper helper, IEnumerable source)
   at BulkCopyRowsCopied LinqToDB.DataProvider.BasicBulkCopy.MultipleRowsCopy1<T>(ITable<T> table, BulkCopyOptions options, IEnumerable<T> source)
   at BulkCopyRowsCopied LinqToDB.DataProvider.PostgreSQL.PostgreSQLBulkCopy.MultipleRowsCopy<T>(ITable<T> table, BulkCopyOptions options, IEnumerable<T> source)
   at BulkCopyRowsCopied LinqToDB.DataProvider.BasicBulkCopy.BulkCopy<T>(BulkCopyType bulkCopyType, ITable<T> table, BulkCopyOptions options, IEnumerable<T> source)
   at BulkCopyRowsCopied LinqToDB.DataProvider.PostgreSQL.PostgreSQLDataProvider.BulkCopy<T>(ITable<T> table, BulkCopyOptions options, IEnumerable<T> source)
   at BulkCopyRowsCopied LinqToDB.Data.DataConnectionExtensions.BulkCopy<T>(DataConnection dataConnection, BulkCopyOptions options, IEnumerable<T> source)
   at BulkCopyRowsCopied LinqToDB.EntityFrameworkCore.LinqToDBForEFTools.BulkCopy<T>(DbContext context, BulkCopyOptions options, IEnumerable<T> source)
  Exception data:
    Severity: ERROR
    SqlState: 42804
    MessageText: column "currency" is of type currency but expression is of type integer
    Hint: You will need to rewrite or cast the expression.
    Position: 832
    File: parse_target.c
    Line: 591
    Routine: transformAssignedExpr

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

sdanylivcommented, Jul 24, 2020

It is more provider specific problem and i need more details.

  • Your Model
  • Table script
  • How you defined enum
  • How you configured EF Core to handle this enum.
  • Why do you use Enum? 😉 joking
MaceWinducommented, Feb 26, 2023

Closing as it looks like all questions resolved.

Some extra notes:

  • there is no need to modify global MappingSchema.Default with new AddMappingSchema configuration API in latest release: you can configure separate mapping schema
  • there is no GlobalTypeMapper anymore in npgsql 7, check this issue for help
Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL enums and composites
PostgreSQL supports enum types and composite types as database columns, and Npgsql supports reading and writing these. This allows you to seamlessly read...
Read more >
npgsql says enum is not registered
I'm trying to insert some data with enums via Npgsql. At first, everything worked fine, but I have noted, that some of my...
Read more >
COPY | Npgsql Documentation
COPY. PostgreSQL has a feature allowing efficient bulk import or export of data to and from a table. This is usually a much...
Read more >
Dealing with Enum Type in PostgreSQL
This is a brief guide for effectively understanding and working with enum type in Postgres: Why does it exist? What does it do?...
Read more >
Create a Custom SQL Enum Type
In this lesson we'll create and assign data to a custom enum type. For more info:; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found