protected static bool Update <T>(string tableName, T model, int whereId, string idname, bool addNullValues, List <string> fields = null, List <string> skipFields = null) where T : new() { if (skipFields == null) { skipFields = new List <string>(); } if (!skipFields.Contains(DatabaseModel.FieldId)) { skipFields.Add(DatabaseModel.FieldId); } PrepSQL sql = new PrepSQL(); sql.ConfigUpdate(model, addNullValues, fields, skipFields); sql.Query = "UPDATE [dbo].[" + tableName + "] SET " + sql.TempSql + " WHERE " + idname + " = @" + idname; sql.ColumnValueList.Add(new KeyValuePair <String, Object>(idname, whereId)); bool ok = sql.Update(); return(ok); }
protected static int Insert <T>(string tableName, T model, bool addNullValues, List <string> fields = null, List <string> skipFields = null, bool skipId = true) where T : new() { if (skipId) { if (skipFields == null) { skipFields = new List <string>(); } if (!skipFields.Contains(DatabaseModel.FieldId)) { skipFields.Add(DatabaseModel.FieldId); } } PrepSQL sql = new PrepSQL(); sql.ConfigInsert(model, addNullValues, fields, skipFields); sql.Query = "INSERT INTO [dbo].[" + tableName + "] " + sql.TempSql; int id = sql.Insert(tableName); return(id); }