question-mark
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.

Question: Is there a way to setup/define dynamic parameter as in Dapper?

See original GitHub issue

I’ve got RAW SQL + expando object with parameters list and in the database field that I’m looking for is of type VARCHAR(200) and my string parameter is parsed by repoDB to NVARCHAR(XXX) which causes slow performance when querying data.

I mitigate this issue by using:

            var @params = new
            {
                Id = id
            };

            TypeMapper.Add<string>(DbType.AnsiString);
            var data = await connection.ExecuteQueryMultipleAsync(query, @params);
            TypeMapper.Remove<string>();

but I’d rather to have something like in dapper:

var parameters = new DynamicParameters();
var customerId = "ALFKI";
parameters.Add("@CustomerId", customerId, DbType.String, ParameterDirection.Input, customerId.Length);
var sql = "select * from customers where CustomerId = @CustomerId";
using (var connection = new SqlConnection(connString))
{
    var customer = connection.QuerySingle<Customer>(sql, parameters);
}

reference: https://www.learndapper.com/parameters

Is it doable in the repodb? Can we select datatype for a query parameters?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikependoncommented, Jul 14, 2022

That would work. We will look on this enhancement request afterwards.

1reaction
rafek1241commented, Jul 14, 2022

Unfortunately using classes and no raw SQL is not an option in the company that I’m working in. I will create enhancement request for QueryField datatype parameter possibility.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create arguments for a Dapper query dynamically
Yes: var dbArgs = new DynamicParameters(); foreach(var pair in args) dbArgs.Add(pair.Key, pair.Value);. Then pass dbArgs in place of args :
Read more >
Dapper Parameter, SQL Injection, Anonymous and ...
Dynamic Parameters create a dynamic object that can be passed to the Query method instead of normal parameters. That is done using the...
Read more >
Working With Parameters In Dapper ORM
Our Project is now ready to work with Dapper ORM, let's add a controller. Right-click on the controller folder >> then Add >>...
Read more >
Learn How to Add Parameter on Demand - Dapper Tutorial
To use Dynamic parameters with Dapper, you need to use the DynamicParameters class. The DynamicParameters class has a dynamic object that ...
Read more >
How to Create Arguments for a Dapper Query Dynamically
In more complicated scenarios, dapper allows the param parameter to be an IDynamicParameters instance. In this case, your custom AddParameters method is ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found