public void Update(T obj) { string tableName = Reflections.GetTableName(typeof(T)); string pk = Reflections.GetPk(typeof(T)); string expression = String.Empty; var dict = obj.GetParamsDict <S>(); var pkWithValue = obj.GetPk <S>(); foreach (var item in dict) { expression += String.Format("{0}=@{0},", item.Key); } dict.Add(pkWithValue.First().Key, pkWithValue.First().Value); expression = expression.Substring(0, expression.Length - 1); //string query = $"Update {tableName} set {expression} where {pk} = @{pk}"; string query = String.Format("Update {0} set {1} where {2} = @{2}", tableName, expression, pk); using (var db = new SqlConnection(_connectionString)) { db.Execute(query, dict); } }
public T GetById(S id) { using (var db = new SqlConnection(_connectionString)) { var data = db.Query <T>(String.Format("{0} where {1} = @id", Reflections.GetQuery(typeof(T)), Reflections.GetPk(typeof(T))), new { id = id }); return(data.SingleOrDefault()); } }
public void Delete(S objId) { using (var db = new SqlConnection(_connectionString)) { db.Execute(String.Format("Delete From {0} where {1} = @id", Reflections.GetTableName(typeof(T)), Reflections.GetPk(typeof(T))), new { id = objId }); } }