//Load all drawings from DB to list of Drawing objects public static List <Drawing> LoadAllDrawings() { SqlBuilder builder = new Dapper.SqlBuilder(); SqlBuilder.Template select = builder.AddTemplate("SELECT * FROM Drawings"); return(QueryDatabase(select)); }
public Task <IEnumerable <Demo> > DemoListByWhere(int obj) { Dapper.SqlBuilder builder = new Dapper.SqlBuilder(); var query = $@"select * from {typeof(Demo).Name} /**where**/ /**orderby**/ "; var template = builder.AddTemplate(query); builder.Where("Age=@a", new { a = obj }); builder.OrderBy("Id"); using (Db.Connection) { var data = this.Db.Connection.QueryAsync <Demo>(template.RawSql, template.Parameters); return(data); } }
//Load from filter using Dapper.SQLBuilder to combine where clauses public static List <Drawing> LoadDrawings(string filter, string starts, string group) { SqlBuilder builder = new Dapper.SqlBuilder(); SqlBuilder.Template select = builder.AddTemplate("SELECT * FROM Drawings /**where**/"); if (!string.IsNullOrEmpty(filter)) { builder.Where($"\"File\" like '{starts}{filter}%'"); } if (!string.IsNullOrEmpty(group)) { builder.Where($"\"Group\" like '{group}'"); } Log.Write.Info(select.RawSql.TrimEnd()); return(QueryDatabase(select)); }