Permalink
Browse files

[Contrib][T4] Column CustomType

  • Loading branch information...
1 parent 8fac7f8 commit e5b0b6ad7503ed31351d4f6239ec1bb01ec65a18 @spaccabit committed Nov 29, 2012
@@ -301,6 +301,9 @@ public string GetMigrationTypeFunctionForType(Column col)
case System.Data.DbType.StringFixedLength:
sysType = string.Format("AsFixedLengthString({0})", sizeStr);
break;
+ case null:
+ sysType = string.Format("AsCustom({0})", col.CustomType);
+ break;
default:
break;
}
@@ -8,6 +8,7 @@ public class Column
public string Name;
public string PropertyName;
public System.Data.DbType? PropertyType;
+ public string CustomType { get; set; }
public bool IsPrimaryKey;
public bool IsNullable;
public bool IsAutoIncrement;
@@ -48,10 +48,14 @@ public override Tables ReadSchema(DbConnection connection, DbProviderFactory fac
var columns = schema.Select("TABLE_NAME='" + item.Name + "'");
foreach (var row in columns)
{
+ var type = GetPropertyType(row);
Column col = new Column();
col.Name = row["COLUMN_NAME"].ToString();
col.PropertyName = CleanUp(col.Name);
- col.PropertyType = GetPropertyType(row);
+ col.PropertyType = type;
+ col.CustomType = type == null
+ ? row["DATA_TYPE"].ToString().ToLowerInvariant()
+ : null;
col.Size = GetDatatypeSize(row["DATA_TYPE"].ToString());
col.Precision = GetDatatypePrecision(row["DATA_TYPE"].ToString());
col.IsNullable = row["IS_NULLABLE"].ToString() == "YES";
@@ -80,10 +80,14 @@ List<Column> LoadColumns(Table tbl)
{
while(rdr.Read())
{
+ var type = this.GetPropertyType(rdr["DataType"].ToString(), (rdr["DataType"] == DBNull.Value ? null : rdr["DataType"].ToString()));
Column col=new Column();
col.Name=rdr["ColumnName"].ToString();
- col.PropertyName=CleanUp(col.Name);
- col.PropertyType=this.GetPropertyType(rdr["DataType"].ToString(), (rdr["DataType"] == DBNull.Value ? null : rdr["DataType"].ToString()));
+ col.PropertyName = CleanUp(col.Name);
+ col.PropertyType = type;
+ col.CustomType = type == null
+ ? rdr["DataType"].ToString().ToLowerInvariant()
+ : null;
col.Size=GetDatatypeSize(rdr["DataType"].ToString());
col.Precision=GetDatatypePrecision(rdr["DataType"].ToString());
col.IsNullable=rdr["IsNullable"].ToString()=="YES";
@@ -77,10 +77,14 @@ List<Column> LoadColumns(Table tbl)
{
while(rdr.Read())
{
+ var type = GetPropertyType(rdr["udt_name"].ToString());
Column col=new Column();
col.Name=rdr["column_name"].ToString();
col.PropertyName=CleanUp(col.Name);
- col.PropertyType=GetPropertyType(rdr["udt_name"].ToString());
+ col.PropertyType = type;
+ col.CustomType = type == null
+ ? rdr["udt_name"].ToString().ToLowerInvariant()
+ : null;
col.Size=GetDatatypeSize(rdr["udt_name"].ToString());
col.Precision=GetDatatypePrecision(rdr["udt_name"].ToString());
col.IsNullable=rdr["is_nullable"].ToString()=="YES";
@@ -77,10 +77,14 @@ List<Column> LoadColumns(Table tbl)
{
while(rdr.Read())
{
+ var type = GetPropertyType(rdr["DataType"].ToString());
Column col=new Column();
col.Name=rdr["ColumnName"].ToString();
col.PropertyName=CleanUp(col.Name);
- col.PropertyType=GetPropertyType(rdr["DataType"].ToString());
+ col.PropertyType=type;
+ col.CustomType = type == null
+ ? rdr["DataType"].ToString().ToLowerInvariant()
+ : null;
col.Size=GetDatatypeSize(rdr["DataType"].ToString());
col.Precision=GetDatatypePrecision(rdr["DataType"].ToString());
col.IsNullable=rdr["IsNullable"].ToString()=="YES";
@@ -83,10 +83,14 @@ List<Column> LoadColumns(Table tbl)
{
while (rdr.Read())
{
+ var type = GetPropertyType(rdr["DataType"].ToString());
Column col = new Column();
col.Name = rdr["ColumnName"].ToString();
col.PropertyName = CleanUp(col.Name);
- col.PropertyType = GetPropertyType(rdr["DataType"].ToString());
+ col.PropertyType = type;
+ col.CustomType = type == null
+ ? rdr["DataType"].ToString().ToLowerInvariant()
+ : null;
col.Size = GetDatatypeSize(rdr["DataType"].ToString());
col.Precision = GetDatatypePrecision(rdr["DataType"].ToString());
col.IsNullable = rdr["IsNullable"].ToString() == "YES";
@@ -60,10 +60,14 @@ List<Column> LoadColumns(Table tbl)
{
while(rdr.Read())
{
+ var type=this.GetPropertyType(rdr["type"].ToString(), (rdr["type"] == DBNull.Value ? null : rdr["type"].ToString()));
Column col=new Column();
col.Name=rdr["name"].ToString();
col.PropertyName=CleanUp(col.Name);
- col.PropertyType=this.GetPropertyType(rdr["type"].ToString(), (rdr["type"] == DBNull.Value ? null : rdr["type"].ToString()));
+ col.PropertyType= type;
+ col.CustomType = type == null
+ ? rdr["type"].ToString().ToLowerInvariant()
+ : null;
col.Size=GetDatatypeSize(rdr["type"].ToString());
col.Precision=GetDatatypePrecision(rdr["type"].ToString());
col.IsNullable=rdr["notnull"].ToString()=="0";

0 comments on commit e5b0b6a

Please sign in to comment.