private string CreateInsertSql(ModelBase model) { var sql = $"INSERT INTO {model.TableName}({{0}}) VALUES({{1}})"; var fields = new StringBuilder(); var values = new StringBuilder(); foreach (dynamic col in model.GetColumnsField()) { if (col is Many2Many || col is Many2One || col is One2Many) { continue; } if (fields.Length == 0) { fields.Append(col.ColumnName); } else { fields.Append("," + col.ColumnName); } if (values.Length == 0) { values.Append(col.ColumnValue); } else { values.Append("," + col.ColumnValue); } } return(string.Format(sql, fields.ToString(), values.ToString())); }
private string GetSelectColumn(ModelBase model, bool isAddm2o, string prefix = "") { var cols = new StringBuilder(); foreach (var col in model.GetColumnsField()) { dynamic sField = col; if (!sField.IsStore) { continue; } var columnName = string.Empty; if (sField is Many2Many || sField is Many2One || sField is One2Many) { if (!isAddm2o) { continue; } if (sField is Many2Many) { } else { columnName = string.Format($"{sField.ColumnName} AS {sField.FieldName}"); } } else { columnName = string.Format($"{sField.ColumnName} AS {sField.FieldName}"); } if (string.IsNullOrEmpty(columnName)) { continue; } if (!string.IsNullOrEmpty(prefix)) { columnName = string.Format($"{prefix}.{columnName}"); } if (cols.Length == 0) { cols.Append(columnName); } else { cols.Append("," + columnName); } } return(cols.ToString()); }