Question: Is there a way to setup/define dynamic parameter as in Dapper?
See original GitHub issueI’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:
- Created a year ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That would work. We will look on this enhancement request afterwards.
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.