/// <summary> /// ColumnModel 赋值 /// </summary> private IList<ModelGeneration> GetColumnModel(IDataReader dr) { var modelList = new List<ModelGeneration>(); while (dr.Read()) { var model = new ModelGeneration(); model.ColumnName = dr["COLUMN_NAME"] == DBNull.Value ? string.Empty : dr["COLUMN_NAME"].ToString(); model.Prec = dr["PREC"] == DBNull.Value ? string.Empty : dr["PREC"].ToString(); model.Scale = dr["SCALE"] == DBNull.Value ? string.Empty : dr["SCALE"].ToString(); model.ColumnComments = dr["COLCOMMENTS"] == DBNull.Value ? string.Empty : dr["COLCOMMENTS"].ToString(); model.DataType = dr["DATA_TYPE"] == DBNull.Value ? string.Empty : dr["DATA_TYPE"].ToString(); model.DataLength = dr["DATA_LENGTH"] == DBNull.Value ? 0 : Convert.ToInt32(dr["DATA_LENGTH"]); model.IsNull = dr["NULLABLE"] == DBNull.Value ? true : dr["NULLABLE"].ToString() == "1" ? true : false; model.IsPrimaryKey = dr["PRIMARYKEY"] == DBNull.Value ? false : dr["PRIMARYKEY"].ToString() == "1" ? true : false; model.DataBaseName = string.Empty; modelList.Add(model); } return modelList; }
/// <summary> /// TableModel 赋值 /// </summary> private IList<ModelGeneration> GetTableModel(IDataReader dr) { var modelList = new List<ModelGeneration>(); while (dr.Read()) { var model = new ModelGeneration(); model.TableName = dr["NAME"] == DBNull.Value ? string.Empty : dr["NAME"].ToString(); model.TableComments = dr["REMARK"] == DBNull.Value ? string.Empty : dr["REMARK"].ToString(); model.TableType = dr["TYPE"] == DBNull.Value ? string.Empty : dr["TYPE"].ToString(); modelList.Add(model); } return modelList; }
/// <summary> /// Sql 字段类型整理 /// </summary> /// <param name="model">Sql字段对象</param> /// <returns></returns> private static string GetSqlTypeAndLength(ModelGeneration model) { switch (model.DataType.ToLower()) { case "numeric": return string.Format("{0}({1},{2})",model.DataType,model.Prec,model.Scale); case "char": case "binary": case "nchar": case "ntext": case "nvarchar": case "varbinary": case "varchar": case "variant": return string.Format("{0}({1})",model.DataType,model.DataLength); case "bigint": case "bit": case "datetime": case "datetime2": case "date": case "datetimeoffset": case "decimal": case "float": case "image": case "int": case "money": case "real": case "smalldatetime": case "smallint": case "smallmoney": case "text": case "time": case "timestamp": case "tinyint": case "udt"://自定义的数据类型 case "uniqueidentifier": case "xml": default: return model.DataType; } }