Skip to content

Instantly share code, notes, and snippets.

@sholfen
Last active May 24, 2019 15:46
Show Gist options
  • Save sholfen/f1fe088f96e5497b51b1bbf704c28453 to your computer and use it in GitHub Desktop.
Save sholfen/f1fe088f96e5497b51b1bbf704c28453 to your computer and use it in GitHub Desktop.
sql builder code for Dapper
public List<T> QueryBy(Dictionary<string, object> dic)
{
string command = $"SELECT * FROM [User]";
Dictionary<string, object> args = new Dictionary<string, object>
{
{"ID1",0 },
{"ID2",1 }
};
var sqlBuilder = new SqlBuilder();
SqlBuilder.Template template = sqlBuilder.AddTemplate($"SELECT * From {typeof(T).Name} /**where**/");
foreach (var pair in dic)
{
sqlBuilder.Where($"{pair.Key} = @{pair.Key}", pair.Value);
}
string sqlcommand = template.RawSql;
//var rows = _connection.Query(template.RawSql, template.Parameters);
return _connection.Query<T>(command).AsList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment