I have a question about how to write SQL's with Dapper.
Now I use something like this:
resultObject result;
String sqlCmd = String.Format("select * from SOME_PROCEDURE('{0}',{1},{2})", Param1, Param2, Param3);
result = FbConnection1.Query<resultObject>(sqlCmd, null).ToList();
But now I see that it is not so clean, And I found a FBCommand
which allow me to use
FbCommand cmd = new FbCommand("select * from SOME_PROCEDURE(@param1, @param2)");
cmd.Parameters.Add("@param1", FbDbType.Integer).Value = value1;
cmd.Parameters.Add("@param2", FbDbType.Integer).Value = value2;
I don't know how to user Dapper with FBCommand, is it possible ? Or maybe using String.Format
for building SQL is good way?
If there is a corresponding FbConnection
, and if that connection is a standard ADO.NET implementation, and if it supports standard parameters, then yes, you could try doing:
using(FbConnection conn = ...)
{
var data = conn.Query<SomeType>(
"select * from SOME_PROCEDURE(@value1, @value2)",
new { value1, value2 }).ToList();
// ...
}
You could also try:
using(FbConnection conn = ...)
{
var data = conn.Query<SomeType>("SOME_PROCEDURE",
new { param1 = value1, param2 = value2 },
commandType: CommandType.StoredProcedure).ToList();
// ...
}