/// <summary> /// 获取表的所有字段名及字段类型 /// </summary> /// <returns></returns> protected List <DbFieldInfo> GetAllColumnsInternal(string sql) { List <DbFieldInfo> list = new List <DbFieldInfo>(); using (DbConnection conn = OpenSharedConnection()) { IEnumerable <dynamic> dlist = conn.Query(sql); foreach (var item in dlist) { DbFieldInfo dbFieldInfo = new DbFieldInfo { FieldName = item.FieldName, //Increment = item.Increment == "1" ? true : false, IsIdentity = item.IsIdentity == "1" ? true : false, FieldType = item.FieldType.ToString(), DataType = item.FieldType.ToString(), FieldMaxLength = item.FieldMaxLength, FieldPrecision = item.FieldPrecision, FieldScale = item.FieldScale, IsNullable = item.IsNullable == "1" ? true : false, FieldDefaultValue = item.FieldDefaultValue, Description = item.Description }; list.Add(dbFieldInfo); } } return(list); }
//所有类型转换 http://www.cnblogs.com/vjine/p/3462167.html /// <summary> /// 将字段信息的类型转换为C#信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public string ConvertDataType(DbFieldInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (string.IsNullOrEmpty(info.FieldType)) { throw new ArgumentNullException(nameof(info.FieldType)); } info.DataType = SqlType2CsharpTypeStr(info.FieldType, info.IsNullable); return(info.DataType); }