Beispiel #1
0
 private void SetDbParams(System.Data.Common.DbConnection conn)
 {
     if (conn.GetType().Name.ToLower().IndexOf("oracle") > -1 || conn.GetType().Name.ToLower().IndexOf("pgsql") > -1)
     {
         dbParamChar = ':';
     }
 }
        public static string GenerateAllTables(this System.Data.Common.DbConnection connection, GeneratorBehavior generatorBehavior = GeneratorBehavior.Default)
        {
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            var conneciontName = connection.GetType().Name.ToLower();
            var tables         = new List <string>();
            var sql            = generatorBehavior.HasFlag(GeneratorBehavior.View) ? TableSchemaSqls[conneciontName].Split("where")[0] : TableSchemaSqls[conneciontName];

            using (var command = connection.CreateCommand(sql))
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tables.Add(reader.GetString(0));
                    }
                }

            var sb = new StringBuilder();

            sb.AppendLine("namespace Models { ");
            tables.ForEach(table => sb.Append(connection.GenerateClass(
                                                  string.Format(QuerySqls[conneciontName], table), table, generatorBehavior: generatorBehavior
                                                  )));
            sb.AppendLine("}");
            return(sb.ToString());
        }
Beispiel #3
0
 public SchemaParameters(System.Data.Common.DbConnection dbConnection)
 {
     DbConnection     = dbConnection;
     ProviderName     = DbConnection.GetType().Namespace;
     ConnectionString = dbConnection.ConnectionString;
     SqlType          = ProviderToSqlType.Convert(ProviderName);
     Exclusions       = new Exclusions();
 }
Beispiel #4
0
        private static ISqlAdapter GetFormatter(IDbConnection connection)
        {
            var name = GetDatabaseType?.Invoke(connection).ToLower()
                       ?? connection.GetType().Name.ToLower();

            return(!AdapterDictionary.ContainsKey(name)
                ? DefaultAdapter
                : AdapterDictionary[name]);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the feature set based on the passed connection
        /// </summary>
        public static FeatureSupport Get(IDbConnection connection)
        {
            string name = connection?.GetType().Name;

            if (string.Equals(name, "npgsqlconnection", StringComparison.OrdinalIgnoreCase))
            {
                return(Postgres);
            }
            return(Default);
        }
Beispiel #6
0
        } // End Static Constructor

        public static System.Data.Common.DbProviderFactory GetProviderByReflection(System.Data.Common.DbConnection conn)
        {
            System.Type t = conn.GetType();
            System.Reflection.PropertyInfo pi = t.GetProperty("DbProviderFactory",
                                                              System.Reflection.BindingFlags.NonPublic
                                                              | System.Reflection.BindingFlags.Instance
                                                              );

            return((System.Data.Common.DbProviderFactory)pi.GetValue(conn));
        } // End Function GetProviderByReflection
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseReader"/> class from a DbConnection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public DatabaseReader(System.Data.Common.DbConnection connection)
        {
            var name = connection.GetType().Namespace;

            _db = new DatabaseSchema(connection.ConnectionString, name);
            _schemaParameters = new SchemaParameters(connection)
            {
                DatabaseSchema = _db
            };
            _readerAdapter = ReaderAdapterFactory.Create(_schemaParameters);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseReader"/> class from a DbConnection.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public DatabaseReader(System.Data.Common.DbConnection connection) :
     this(connection.GetType().Namespace, connection.ConnectionString, new SchemaParameters(connection))
 {
 }