2

Let's say I have a user defined data type in the database: MySuperType which as two bigint properties in it (Id + Code)

And I have a stored procedure which takes in those parameters:

@MySuperType, @Price, @dateModified, etc...

Now in my code, I am using Dapper like this:

using (var connecion = new SqlConnection(_connectionString))
{
    result = connection.Execute("SP_name", 
                new {mySuperType, price, date}, 
                commandType: CommandType.StoredProcedure);
}

But I keep getting an error

Type Operand clash: Dapper is not able to map the user defined type: MySuperType from the parameters to the stored procedure.

Changing the stored procedure or replacing the user-defined type isn't an option

Does anyone have an idea what I can do to map the types and send the parameters (all of them) to the stored procedure?

1 Answer 1

1

Tha names of parameters must correspond to parameters defined in procedure:

using (var connecion = new SqlConnection(_connectionString))
        {
            result = connection.Execute("SP_name", 
                new {MySuperType = mySuperType, Price = price, dateModified = date}, 
                commandType: CommandType.StoredProcedure);
        }

Dapper is case sensitive in mapping in 2 directions (as parameters and as results).

If you want to avoid specifying names of the parameters, make sure you have it exactly same in variables in c# and stored procedure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.