Skip to content

TypeHandler not working correctly with DynamicParameters #275

@ylibrach

Description

@ylibrach

It appears that when executing a stored procedure and feeding parameters in through a DynamicParameters object, the command will fail if one of the parameters is set to a type that has a TypeHandler set on SqlMapper.

It appears that Dapper never makes a check to establish whether there is an associated TypeHandler for the parameter (no calls against the Dictionary happen). The error is: No mapping exists from object type [ObjectType] to a known managed provider native type. Relevant stack trace is as follows:

   at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)  
   at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
   at System.Data.SqlClient.SqlParameter.get_DbType()
   at Dapper.DynamicParameters.AddParameters(IDbCommand command, Identity identity) in [..]\Dapper.cs:line 4677
   at Dapper.DynamicParameters.Dapper.SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, Identity identity) in [..]\Dapper.cs:line 4569
   at Dapper.SqlMapper.<>c__DisplayClass52.<GetCacheInfo>b__4d(IDbCommand cmd, Object obj) in [..]\Dapper.cs:line 2091
   at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader) in [..]\Dapper.cs:line 177
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in [..]\Dapper.cs:line 3313
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in [..]\Dapper.cs:line 1309
   at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) in [..]\Dapper.cs:line 1183 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions