private string GenColumnCreateTableSql(ColumnFieldDefinition cfd) { GenCreateSqlFuncDic(); if (!createSqlFuncDic.ContainsKey(cfd.FieldType)) { throw new NLORM.Core.Exceptions.NLORMException("SG", "NOT SUPPORT DBTYPE"); } return(createSqlFuncDic[cfd.FieldType](cfd)); }
private void AsignColTypeAttrToDef(ColumnFieldDefinition colunmF, ColumnTypeAttribute colTypeAttr, PropertyInfo prop) { if (colTypeAttr != null) { colunmF.PropName = prop.Name; colunmF.FieldType = colTypeAttr.DBType; colunmF.Length = colTypeAttr.Length; colunmF.Nullable = colTypeAttr.Nullable; colunmF.Comment = colTypeAttr.Comment; } else { colunmF.PropName = prop.Name; colunmF.FieldType = Dapper.SqlMapper.LookupDbType(prop.PropertyType, prop.Name); } }
private string GenCreateSqlByType(ColumnFieldDefinition cfd, string type, string length = "") { var ret = ""; ret += " " + cfd.ColumnName + " "; var nullable = cfd.Nullable ? "" : "not null"; if (string.IsNullOrEmpty(length)) { ret += type + " " + nullable; } else { ret += type + "(" + length + ") " + nullable; } return(ret); }
private ColumnFieldDefinition GetColumnFieldDefByProprty(PropertyInfo prop) { object[] attrs = prop.GetCustomAttributes(true); var ret = new ColumnFieldDefinition(); ColumnNameAttribute colNameAttr = null; ColumnTypeAttribute colTypeAttr = null; foreach (object attr in attrs) { if (attr.GetType().Equals(typeof(ColumnNameAttribute))) { colNameAttr = attr as ColumnNameAttribute; } if (attr.GetType().Equals(typeof(ColumnTypeAttribute))) { colTypeAttr = attr as ColumnTypeAttribute; } } AsignColNameAttrToDef(ret, colNameAttr, prop); AsignColTypeAttrToDef(ret, colTypeAttr, prop); return(ret); }
private void AsignColNameAttrToDef(ColumnFieldDefinition colunmF, ColumnNameAttribute colNameAttr, PropertyInfo prop) { colunmF.ColumnName = colNameAttr == null ? prop.Name : colNameAttr.ColumnName; }
virtual public string GenCreateBigint(ColumnFieldDefinition cfd) { return(GenCreateSqlByType(cfd, "bigint", null)); }
virtual public string GenCreateTime(ColumnFieldDefinition cfd) { return(GenCreateSqlByType(cfd, "time", null)); }
virtual public string GenCreateReal(ColumnFieldDefinition cfd) { return(GenCreateSqlByType(cfd, "real", null)); }
virtual public string GenCreateDecimal(ColumnFieldDefinition cfd) { var length = string.IsNullOrEmpty(cfd.Length) ? StringDeafultLength : cfd.Length; return(GenCreateSqlByType(cfd, "decimal", length)); }
virtual public string GenCreateDateTime(ColumnFieldDefinition cfd) { return(GenCreateSqlByType(cfd, "DATETIME")); }
virtual public string GenCreateInteger(ColumnFieldDefinition cfd) { return(GenCreateSqlByType(cfd, "INTEGER")); }