I want to write a query with a dynamic list of parameters (depending on parameter is set or not). I want to execute the query on an oracle database using dapper.
Sample code:
var sqlParams = new List<object>();
var sqlBuilder = new StringBuilder();
sqlBuilder.Append("SELECT * FROM EXAMPLE WHERE 1 = 1 ");
if (!string.IsNullOrEmpty(aParam))
{
sqlBuilder.Append(" AND A LIKE ?");
}
if (!string.IsNullOrEmpty(bParam))
{
sqlBuilder.Append(" AND B LIKE ? ");
}
var sql = sqlBuilder.ToString();
return this.Connection.Query<Equipment>(
sql,
new { aParam, bParam } // ??
).ToList();