Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: The ENUM type of Postgre (DB) is not being handled properly in RepoDb.PostgreSql. #395 #854

Closed
mikependon opened this issue Aug 6, 2021 · 3 comments
Assignees
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed.

Comments

@mikependon
Copy link
Owner

Reported by @orthoxerox at #395.

@mikependon This still doesn't work if the enum is used in the where clause:

var people = connection.Query<Person>(where: p => p.DominantHand == Hand.Right);
//I've been renaming stuff to understand why my main program failed when this snipped didn't

results in:

Unhandled exception. System.InvalidCastException: Can't write CLR type Sandbox.Program+Hand with handler type TextHandler
   at lambda_method5(Closure , NpgsqlTypeHandler , Object , NpgsqlLengthCache& , NpgsqlParameter )
   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.ValidateObjectAndGetLength(Object value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter)
   at Npgsql.NpgsqlParameter.ValidateAndGetLength()
   at Npgsql.NpgsqlCommand.ValidateParameters(ConnectorTypeMapper typeMapper)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at RepoDb.DbConnectionExtension.ExecuteQueryInternalForType[TResult](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, String tableName, Boolean skipCommandArrayParametersCheck)
   at RepoDb.DbConnectionExtension.ExecuteQueryInternal[TResult](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, String tableName, Boolean skipCommandArrayParametersCheck)
   at RepoDb.DbConnectionExtension.QueryInternalBase[TEntity](IDbConnection connection, String tableName, QueryGroup where, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.QueryInternal[TEntity](IDbConnection connection, String tableName, QueryGroup where, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
   at RepoDb.DbConnectionExtension.Query[TEntity](IDbConnection connection, Expression`1 where, IEnumerable`1 fields, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Nullable`1 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder)
   at Sandbox.Program.QueryPeople() in C:\...\Sandbox\Program.cs:line 99
   at Sandbox.Program.Main(String[] args) in C:\...\Sandbox\Program.cs:line 41
@mikependon mikependon added the bug Something isn't working label Aug 6, 2021
@mikependon mikependon self-assigned this Aug 6, 2021
@mikependon
Copy link
Owner Author

@orthoxerox, please continue here.

@orthoxerox
Copy link
Contributor

orthoxerox commented Aug 6, 2021

One more thing: Nullable<SomeEnum> doesn't work either. I'll push a branch with failing tests to my fork in a few hours.

Upd: #855

@mikependon mikependon pinned this issue Sep 10, 2021
@mikependon mikependon added the fixed The bug, issue, incident has been fixed. label Sep 10, 2021
@mikependon mikependon unpinned this issue Sep 10, 2021
@mikependon mikependon added the deployed Feature or bug is deployed at the current release label Sep 23, 2021
@epicbugs
Copy link

The error is still happening with RepoDb.PostgreSql (1.1.4) and integer type column in database.

System.InvalidCastException: Can't write CLR type SomeEnum with handler type Int32Handler

Only workaround I found was to implement IPropertyHandler<int, T> where T : Enum.

Would it be possible to have some bugfix or feature so that no handler is required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed.
Projects
None yet
Development

No branches or pull requests

3 participants