private static string FormatDBDataType(Column col) { var dbTypeSpec = string.Empty; switch (col.DBDataType.ToLower()) { case "bigint": case "binary": case "bit": case "datetime": case "smalldatetime": case "date": case "decimal": case "float": case "image": case "int": case "money": case "numeric": case "smallmoney": case "real": case "smallint": case "sql_variant": case "timestamp": case "tinyint": case "uniqueidentifier": case "varbinary": dbTypeSpec = col.DBDataType; break; case "char": case "ntext": case "nvarchar": case "sysname": case "text": case "varchar": var myString = col.DBDataType.ToLower(); var maxLen = (col.MaxLength <= 0) ? "MAX" : col.MaxLength.ToString(); myString += string.Format("({0})", maxLen); dbTypeSpec = myString; break; } if (col.IsNullable == false) { dbTypeSpec += " NOT NULL "; } return dbTypeSpec; }
private string GetMappingLineForColumn(Column column) { string source = string.Format("\t\t\tMap(x => x.{0}, \"{1}\")", column.Name, column.Name); if (column.IsNullable == false) { source += ".Not.Nullable()"; } if (column.MaxLength > 0) { source += string.Format(".Length({0})", column.MaxLength); } source += ";\r\n"; return source; }
// Note: Maybe make a class in AbstractGenerator to generically write a property declaration private static string WriteColumnProperty(Column col) { return string.Format("\t\tpublic {0} {1} {2} get; set; {3}\r\n\r\n", GetCSDataType(col), col.Name, "{", "}"); }
private static string WriteColumnAttribute(Column col, Table tbl) { var dbType = FormatDBDataType(col); var canBeNull = string.Empty; if (col.IsNullable == false) { canBeNull = ", CanBeNull=false"; } var isPrimaryKey = string.Empty; if (col.IsPrimaryKey || (tbl.PrimaryKeys != null && tbl.PrimaryKeys.SingleOrDefault(p => p.ColumnName == col.Name) != default(PrimaryKey))) { isPrimaryKey = ", IsPrimaryKey=true"; } var retString = string.Format("\t\t[Column(Name=\"{0}\", DBType=\"{1}\" {2} {3})]\r\n", col.Name, dbType, canBeNull, isPrimaryKey); return retString; }
private static string GetCSDataType(Column col) { switch (col.DBDataType.ToLower()) { case "bigint": return "long"; case "binary": return "byte[]"; case "bit": return "bool"; case "datetime": case "smalldatetime": case "date": return "DateTime"; case "decimal": return "decimal"; case "float": return "double"; case "image": return "byte[]"; case "int": return "int"; case "money": case "numeric": case "smallmoney": return "decimal"; case "char": case "ntext": case "nvarchar": case "sysname": case "text": case "varchar": return "string"; case "real": return "float"; case "smallint": return "short"; case "sql_variant": return "object"; case "timestamp": return "long"; case "tinyint": return "byte"; case "uniqueidentifier": return "Guid"; case "varbinary": return "byte[]"; } return "string"; // just doing this for now will work up a method later. }