private List <SColumn> GetBaseColumns(DbConn dbconn, string tableid) { string sql = @"select SC.object_id,SC.name,SC.column_id,SC.user_type_id,ST.name as typename, SC.max_length,SC.precision,SC.scale,SC.is_nullable, SC.is_identity,IC.seed_value,IC.increment_value,IC.last_value, SC.default_object_id,DFC.definition,EP.value as des from sys.all_columns SC left join sys.types ST on SC.user_type_id=ST.user_type_id left join sys.identity_columns IC on SC.object_id=IC.object_id and SC.column_id=IC.column_id left join sys.default_constraints DFC on SC.default_object_id=DFC.object_id left join sys.extended_properties EP on EP.minor_id=SC.column_id and SC.object_id=EP.major_id and EP.name='MS_Description' where SC.object_id=@objid"; DataTable tbcolumns = dbconn.SqlToDataTable(sql, new { objid = tableid }); List <SColumn> columns = new List <SColumn>(); foreach (DataRow dr in tbcolumns.Rows) { string desc = dr["des"].ToString(); FieldType fieldtype = DbFieldTypeHelper.SqlServerGetFieldType( dr["typename"].ToString(), Convert.ToInt32(dr["precision"]), Convert.ToInt32(dr["scale"]), Convert.ToInt32(dr["max_length"])); columns.Add(new SColumn() { name = dr["name"].ToString(), allownull = Utils.Converter.ObjToBool(dr["is_nullable"]), description = desc, title = string.IsNullOrEmpty(desc) ? dr["name"].ToString() : desc, isidentity = Utils.Converter.ObjToBool("is_identity"), filedtype = fieldtype }); } return(columns); }
public void ToLocalTable(STable other, List <SqlToSqlModel> sqltypemodel, bool autofieldtypechange) { foreach (var a in other.columns) { foreach (var b in sqltypemodel) { if (a.filedtype.name == b.typename1) { a.filedtype = DbFieldTypeHelper.SqlServerGetFieldType(b.typename2, a.filedtype.precision, a.filedtype.scale, a.filedtype.maxlength); break; } } throw new Exception(a.filedtype.name + "不存在转化"); } }