public static string GenerateUpdateFields(DatabaseModel model) { StringBuilder StringBuilder = new StringBuilder(); foreach (PropertyInfo property in model.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | BindingFlags.Instance)) { CustomAttributeData l_ExcludeFromUpdate = property.CustomAttributes.FirstOrDefault(customAttributes => customAttributes.AttributeType == typeof(TableFieldExcludeFromUpdateAttribute)); if (l_ExcludeFromUpdate != null && Convert.ToBoolean(l_ExcludeFromUpdate.ConstructorArguments.First().Value)) { continue; } CustomAttributeData l_TableFieldName = property.CustomAttributes.FirstOrDefault(customAttributes => customAttributes.AttributeType == typeof(TableFieldNameAttribute)); if (l_TableFieldName == null) { continue; } string FieldName = (string)l_TableFieldName.ConstructorArguments.First().Value; object FieldValue = property.GetValue(model); StringBuilder.Append(StringBuilder.Length == 0 ? $"{FieldName} = {MySQLDBCommon.SetValueForSql(FieldValue)}" : $", {FieldName} = {MySQLDBCommon.SetValueForSql(FieldValue)}"); } return(StringBuilder.ToString()); }
public static List <object> ModelFieldValues(object model) { List <object> ModelFieldValues = new List <object>(); foreach (var properties in model.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | BindingFlags.Instance)) { object Value = properties.GetValue(model); ModelFieldValues.Add(MySQLDBCommon.SetValueForSql(Value)); } return(ModelFieldValues); }
public static string GenerateStandardDeleteStatement(DatabaseModel model, string primaryKeyFieldName, object primaryKeyValue) { return($"DELETE FROM {model.TableName()} WHERE {GetDatabaseTableFieldName(model, primaryKeyFieldName)} = {MySQLDBCommon.SetValueForSql(primaryKeyValue)}"); }
public static string GenerateStandardUpdateStatement(DatabaseModel model, string primaryKeyFieldName, object primaryKeyValue) { return($"UPDATE {model.TableName()} SET {GenerateUpdateFields(model)} WHERE {GetDatabaseTableFieldName(model, primaryKeyFieldName)} = {MySQLDBCommon.SetValueForSql(primaryKeyValue)}"); }