//获取存储过程
        private static List <StoredProcedure> LoadStoredProcs(DbProviderFactory factory)
        {
            if (factory == null || !ElementsToGenerate.HasFlag(Elements.StoredProcedures))
            {
                return(new List <StoredProcedure>());
            }

            try
            {
                using (DbConnection conn = factory.CreateConnection())
                {
                    conn.ConnectionString = ConnectionString;
                    conn.Open();

                    if (conn.GetType().Name == "SqlCeConnection")
                    {
                        return(new List <StoredProcedure>());
                    }

                    var reader = new SqlServerSchemaReader(conn, factory, IncludeQueryTraceOn9481Flag)
                    {
                        Outer = null
                    };
                    var storedProcs = reader.ReadStoredProcs(StoredProcedureFilterExclude, UseCamelCase, PrependSchemaName, StoredProcedureRename, SchemaName);

                    // Remove unrequired stored procs
                    for (int i = storedProcs.Count - 1; i >= 0; i--)
                    {
                        if (SchemaName != null && String.Compare(storedProcs[i].Schema, SchemaName, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            storedProcs.RemoveAt(i);
                            continue;
                        }
                        if (StoredProcedureFilterInclude != null && !StoredProcedureFilterInclude.IsMatch(storedProcs[i].Name))
                        {
                            storedProcs.RemoveAt(i);
                            continue;
                        }
                    }

                    foreach (var proc in storedProcs)
                    {
                        reader.ReadStoredProcReturnObject(ConnectionString, proc);
                    }

                    conn.Close();
                    return(storedProcs);
                }
            }
            catch (Exception x)
            {
                string error = x.Message.Replace("\r\n", "\n").Replace("\n", " ");
                Console.WriteLine(string.Format("Failed to read database schema for stored procedures - {0}", error));
                Console.WriteLine("");
                Console.WriteLine("// -----------------------------------------------------------------------------------------");
                Console.WriteLine("// Failed to read database schema for stored procedures - {0}", error);
                Console.WriteLine("// -----------------------------------------------------------------------------------------");
                Console.WriteLine("");
                return(new List <StoredProcedure>());
            }
        }
        //获取表
        public static Tables LoadTables(DbProviderFactory factory)
        {
            if (factory == null || !(ElementsToGenerate.HasFlag(Elements.Poco) ||
                                     ElementsToGenerate.HasFlag(Elements.Context) ||
                                     ElementsToGenerate.HasFlag(Elements.UnitOfWork) ||
                                     ElementsToGenerate.HasFlag(Elements.PocoConfiguration)))
            {
                return(new Tables());
            }

            try
            {
                using (DbConnection conn = factory.CreateConnection())
                {
                    conn.ConnectionString = ConnectionString;
                    conn.Open();

                    bool isSqlCE = false;
                    if (conn.GetType().Name == "SqlCeConnection")
                    {
                        PrependSchemaName = false;
                        isSqlCE           = true;
                    }

                    SchemaReader reader = null;
                    if (CodeFirstTools.DataType.ToLower() == "oracle")
                    {
                        reader = new OracleSchemaReader(conn, factory);
                    }
                    else
                    {
                        reader = new SqlServerSchemaReader(conn, factory, IncludeQueryTraceOn9481Flag)
                        {
                            Outer = null
                        };
                    }

                    var tables = reader.ReadSchema(TableFilterExclude, ColumnFilterExclude, UseCamelCase, PrependSchemaName, IncludeComments, IncludeExtendedPropertyComments, TableRename, SchemaName, UpdateColumn);
                    tables.SetPrimaryKeys();

                    // Remove unrequired tables/views
                    for (int i = tables.Count - 1; i >= 0; i--)
                    {
                        if (SchemaName != null && String.Compare(tables[i].Schema, SchemaName, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            tables.RemoveAt(i);
                            continue;
                        }
                        if (!IncludeViews && tables[i].IsView)
                        {
                            tables.RemoveAt(i);
                            continue;
                        }
                        if (TableFilterInclude != null && !TableFilterInclude.IsMatch(tables[i].Name))
                        {
                            tables.RemoveAt(i);
                            continue;
                        }
                        if (!tables[i].IsView && string.IsNullOrEmpty(tables[i].PrimaryKeyNameHumanCase()))
                        {
                            tables.RemoveAt(i);
                        }
                    }

                    // Must be done in this order
                    var fkList = reader.ReadForeignKeys(TableRename);
                    reader.IdentifyForeignKeys(fkList, tables);
                    reader.ProcessForeignKeys(fkList, tables, UseCamelCase, PrependSchemaName, CollectionType, true, IncludeComments);
                    tables.IdentifyMappingTables(fkList, UseCamelCase, CollectionType, true, IncludeComments, isSqlCE);

                    tables.ResetNavigationProperties();
                    reader.ProcessForeignKeys(fkList, tables, UseCamelCase, PrependSchemaName, CollectionType, false, IncludeComments);
                    tables.IdentifyMappingTables(fkList, UseCamelCase, CollectionType, false, IncludeComments, isSqlCE);

                    // Remove views that only consist of all nullable fields.
                    // I.e. they do not contain any primary key, and therefore cannot be used by EF
                    for (int i = tables.Count - 1; i >= 0; i--)
                    {
                        if (string.IsNullOrEmpty(tables[i].PrimaryKeyNameHumanCase()))
                        {
                            tables.RemoveAt(i);
                        }
                    }

                    conn.Close();
                    return(tables);
                }
            }
            catch (Exception x)
            {
                string error = x.Message.Replace("\r\n", "\n").Replace("\n", " ");
                Console.WriteLine(string.Format("Failed to read database schema - {0}", error));
                Console.WriteLine("");
                Console.WriteLine("// -----------------------------------------------------------------------------------------");
                Console.WriteLine("// Failed to read database schema - {0}", error);
                Console.WriteLine("// -----------------------------------------------------------------------------------------");
                Console.WriteLine("");
                //return new Tables();
                throw x;
            }
        }