예제 #1
0
        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());
        }
예제 #2
0
        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);
        }
예제 #3
0
 public static string GenerateStandardDeleteStatement(DatabaseModel model, string primaryKeyFieldName, object primaryKeyValue)
 {
     return($"DELETE FROM {model.TableName()} WHERE {GetDatabaseTableFieldName(model, primaryKeyFieldName)} = {MySQLDBCommon.SetValueForSql(primaryKeyValue)}");
 }
예제 #4
0
 public static string GenerateStandardUpdateStatement(DatabaseModel model, string primaryKeyFieldName, object primaryKeyValue)
 {
     return($"UPDATE {model.TableName()} SET {GenerateUpdateFields(model)} WHERE {GetDatabaseTableFieldName(model, primaryKeyFieldName)} = {MySQLDBCommon.SetValueForSql(primaryKeyValue)}");
 }