Replies: 10 comments
-
if you are building the query then it's simple: var query = SQL
.SELECT("SQL_CALC_ROWS *")
... if you are getting the query from var query = db.Products.SQL
.SELECT_FROM()
.Insert(6, " SQL_CALC_ROWS")
... same thing if you are using var query = db.Products.GetDefiningQuery()
.Insert(6, " SQL_CALC_ROWS")
... |
Beta Was this translation helpful? Give feedback.
-
I did the following:
|
Beta Was this translation helpful? Give feedback.
-
Could you give me an example how to format the following query:
when I have int[] params = new int[] { 10, 11 } with _OR<>() method extension. I read the documentation but did not understand from Samples.cs example. |
Beta Was this translation helpful? Give feedback.
-
var query = SQL
...
.WHERE("(a = 1 AND (b = {0} OR c = {1}) AND d = 2)", params[0], params[1]) The _OR method is for cases when the number of parameters is not known until runtime, is that your case? |
Beta Was this translation helpful? Give feedback.
-
I did the following, but it seems like some workaround.
|
Beta Was this translation helpful? Give feedback.
-
This would be the way to do it: ...
.WHERE()
._OR(q.Types, "type = {0}", p => new object[] { p[0] }) The first parameter is the collection of items, the second is the SQL template for each item, and the third is a delegate that returns the parameters used in the template for each item. To integrate with Dapper you could call |
Beta Was this translation helpful? Give feedback.
-
Thanks, that worked! |
Beta Was this translation helpful? Give feedback.
-
As I was not been able to integrate Dapper so I wrote myself an extension method to return string with parameters already applied. Dapper uses parameters like "type = @type" so they do not collide.
|
Beta Was this translation helpful? Give feedback.
-
Watch out for SQL injection when using string parameters. |
Beta Was this translation helpful? Give feedback.
-
Yes. At the moment only string parameters come from DateTime.ToShortDateString(). User input strings will be passed through Dapper. |
Beta Was this translation helpful? Give feedback.
-
How to add SQL_CALC_ROWS parameter to query?
Beta Was this translation helpful? Give feedback.
All reactions