public static DbType GetDbType(this Field field) { switch (field.DataType) { case "bigint": return(DbType.Int64); case "binary": case "varbinary": case "image": case "timestamp": return(DbType.Binary); case "bit": return(DbType.Boolean); case "char": case "varchar": case "text": return(DbType.AnsiString); case "nchar": case "nvarchar": case "ntext": return(DbType.String); case "xml": return(DbType.Xml); case "date": return(DbType.Date); case "datetime2": return(DbType.DateTime2); case "time": return(DbType.Time); case "datetime": case "smalldatetime": return(DbType.DateTime); case "int": return(DbType.Int32); case "smallint": return(DbType.Int16); case "tinyint": return(DbType.Byte); case "real": return(DbType.Single); case "float": case "numeric": return(DbType.Double); case "decimal": return(DbType.Decimal); case "money": case "smallmoney": return(DbType.Currency); case "uniqueidentifier": return(DbType.Guid); default: return(DbType.Object); } }
public static string GetSqlDataType(this Field field) { switch (field.DataType) { case "bigint": return("bigint"); case "binary": return(string.Format("binary({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "varbinary": return(string.Format("varbinary({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "image": return("image"); case "bit": return("bit"); case "char": return(string.Format("char({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "varchar": return(string.Format("varchar({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "nchar": return(string.Format("nchar({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "nvarchar": return(string.Format("nvarchar({0})", field.Length == -1 ? "max" : field.Length.ToString())); case "text": return("text"); case "ntext": return("ntext"); case "xml": return("xml"); case "date": return("date"); case "time": return("time"); case "datetime": return("datetime"); case "datetime2": return("datetime2"); case "smalldatetime": return("smalldatetime"); case "timestamp": return("timestamp"); case "datetimeoffset": return("datetimeoffset"); case "int": return("int"); case "smallint": return("smallint"); case "tinyint": return("tinyint"); case "float": return("float"); case "real": return("real"); case "numeric": return(string.Format("numeric({0}, {1})", field.Precision, field.scale)); case "decimal": return(string.Format("decimal({0}, {1})", field.Precision, field.scale)); case "money": return("money"); case "smallmoney": return("smallmoney"); case "uniqueidentifier": return("uniqueidentifier"); default: return("object"); } }