예제 #1
0
        void WriteProperty(StreamWriter writer, MyColumn column)
        {
            List <string> avoid = new List <string>(new string[] { "G3E_FID", "G3E_ID", "G3E_FNO" });

            if (column.Table.HasGeometry)
            {
                avoid.Add("G3E_GEOMETRY");
            }
            if (!column.Table.ClassName.ToUpper().StartsWith("CD_") && avoid.Contains(column.Name))
            {
                return;
            }
            if (column.Table.PrimaryKey.Contains(column))
            {
                writer.WriteLine("        [KeyField]");
            }
            if (column.IsSelectOnly)
            {
                writer.WriteLine("        [SelectOnly]");
            }
            if (column.NumericPrecision.HasValue)
            {
                writer.WriteLine(string.Format("        [Precision({0})]", column.NumericPrecision));
            }

            writer.WriteLine(string.Format("        public {0}{1} {2} {{ get; set; }}", column.TypeName, column.IsNullable && column.TypeName != "string"  ?"?":string.Empty, column.Name));
        }
예제 #2
0
        protected override void FillTableDescription(MyTable table)
        {
            using (OracleConnection conn = new OracleConnection(GetConnectString()))
            {
                var cmd        = conn.CreateCommand();
                var isGeometry = table.Name.EndsWith("_SDOGEOM");
                var user       = table.User;//isGeometry ? "CADGIS" : "GZDLGIS";
                cmd.CommandText = string.Format("SELECT COLUMN_NAME,DATA_TYPE,OWNER FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='{0}' AND OWNER ='{1}'", table.Name, user);
                table.Name      = string.Format("{0}.{1}", user, table.Name);
                conn.Open();
                var reader  = cmd.ExecuteReader();
                var columns = new List <string>();
                while (reader.Read())
                {
                    var columnName = reader["COLUMN_NAME"].ToString();
                    if (reader["DATA_TYPE"].ToString() == "SDO_GEOMETRY")
                    {
                        table.Columns.Add(new MyColumn {
                            Name = columnName, TypeName = GetTypeName("SDO_GEOMETRY"), Table = table
                        });
                    }
                    else
                    {
                        columns.Add(reader["COLUMN_NAME"].ToString());
                    }
                }
                //"_SDOGEOM"
                string sql           = string.Format("SELECT {0} FROM {1}", string.Join(",", columns.ToArray()), table.Name);
                string updateViewSql = string.Format("select COLUMN_NAME from all_tab_columns where table_name ='{0}'", table.UpdateView);
                //conn.Open();
                var testCmd = conn.CreateCommand();
                testCmd.CommandText = sql;
                var testReader = testCmd.ExecuteReader();

                var testUpdateViewCmd = conn.CreateCommand();
                testUpdateViewCmd.CommandText = updateViewSql;
                var testUpdateViewReader = testUpdateViewCmd.ExecuteReader();

                var schemaTable = testReader.GetSchemaTable();

                DataTable updateViewSchemaTable = null;
                if (testUpdateViewReader != null)
                {
                    updateViewSchemaTable = GetUpdateViewColumns(testUpdateViewReader);
                }
                IList <MyColumn> selectOnlyColumns = updateViewSchemaTable != null
                                                        ? GetSelectOnlyColumns(schemaTable
                                                                               , updateViewSchemaTable)
                                                        : new List <MyColumn>();

                if (schemaTable != null)
                {
                    foreach (DataRow row in schemaTable.Rows)
                    {
                        var dataType = row["DataType"] as Type;
                        var isNull   = ((bool)row["AllowDBNull"]) && dataType != typeof(string);
                        var column   = new MyColumn
                        {
                            Name       = row["ColumnName"].ToString(),
                            TypeName   = dataType.ToString(),
                            IsNullable = isNull,
                            Table      = table,
                            IsKey      = !row.IsNull("IsKey") && (bool)row["IsKey"]
                        };

                        if (row.IsNull("NumericPrecision"))
                        {
                            column.NumericPrecision = null;
                        }
                        else
                        {
                            column.NumericPrecision = Math.Min((short)row["NumericPrecision"], (short)29);
                        }
                        column.IsSelectOnly = IsSelectOnly(column, selectOnlyColumns);
                        table.Columns.Add(column);
                    }
                }

                /*
                 * COLUMN_NAME
                 * DATA_TYPE
                 * DATA_LENGTH
                 * NULLABLE
                 */
                //while (reader.Read())
                //{
                //    var dataType = reader["DATA_TYPE"].ToString();
                //    decimal? scale = reader["DATA_SCALE"] as decimal?;
                //    string typename = (dataType == "NUMBER" && scale.HasValue && (int)(decimal)reader["DATA_SCALE"] > 0) ? "double":GetTypeName(dataType);

                //    MyColumn column = new MyColumn
                //    {
                //        Name = reader["COLUMN_NAME"].ToString(),
                //        TypeName = typename,
                //        IsNullable = reader["NULLABLE"].ToString() == "Y" && typename != "Geometry"

                //    };

                //    table.Columns.Add(column);
                //}
            }
            table.PrimaryKey.AddRange(GetPrimayColumns(table));
            table.Columns.Sort((o1, o2) => o1.Name.CompareTo(o2.Name));
        }
예제 #3
0
 protected abstract bool IsSelectOnly(MyColumn column, IList <MyColumn> columns);
예제 #4
0
 protected override bool IsSelectOnly(MyColumn column, IList <MyColumn> columns)
 {
     return(columns.Contains(column));
 }