You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but when running a Dapper SQL query that uses a collection type parameter, not a singular parameter - let's say with criteria
"WHERE entity_id = ANY(@entityIds)"
Dapper (with Npgsql data access) throws the following exception:
System.InvalidCastException
Writing values of '<>z__ReadOnlySingleElementList`1[[Domain.Types.MyId]]' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..
at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable`1 pgTypeId, Nullable`1 npgsqlDbType, Exception inner)
at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable`1 pgTypeId, PgSerializerOptions options, Nullable`1 npgsqlDbType)
at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)
at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434
(this particular parameter was [new MyId(value)]) but it fails same way for every collection type.
A workaround I'm using currently is instead passing the collection parameters in as
entityIds=ids.Select(i=>i.value).ToArray()
I was looking how the dapper template would need to be extended to cater for collection parameters but failed to get it to work.
The text was updated successfully, but these errors were encountered:
<>z__ReadOnlySingleElementList1[[Domain.Types.MyId]]` is characteristic of a collection generated by collection-expressions 🤔 I wonder if the problem is purely Dapper's support for the collection type...
For example, what happens if you explicitly define entityIds as an MyId[]?
I don't think this points to an issue in StronglyTypedId, but I'm not 100% 🤔
I might be hitting a bug in Dapper, as I haven't found a nice way to resolve this.
I've got an ID type:
and register the generated
TypeHandler
:but when running a Dapper SQL query that uses a collection type parameter, not a singular parameter - let's say with criteria
"WHERE entity_id = ANY(@entityIds)"
Dapper (with Npgsql data access) throws the following exception:
(this particular parameter was
[new MyId(value)]
) but it fails same way for every collection type.A workaround I'm using currently is instead passing the collection parameters in as
I was looking how the dapper template would need to be extended to cater for collection parameters but failed to get it to work.
The text was updated successfully, but these errors were encountered: