Esempio n. 1
0
 public SchemaParameters(string connectionString, string provider)
 {
     ConnectionString = connectionString;
     ProviderName     = provider;
     SqlType          = ProviderToSqlType.Convert(ProviderName);
     Exclusions       = new Exclusions();
 }
Esempio n. 2
0
        private string WriteDbContext(FileSystemInfo directory, ProjectWriter projectWriter)
        {
            var writer = new CodeFirstContextWriter(_codeWriterSettings);

            if (ProviderToSqlType.Convert(_schema.Provider) == SqlType.Oracle)
            {
                writer.IsOracle = true;
                projectWriter.AddDevartOracleReference();
            }
            var databaseTables = _schema.Tables.Where(t => !FilterIneligible(t))
                                 .ToList();

            if (_codeWriterSettings.IncludeViews)
            {
                databaseTables.AddRange(_schema.Views.OfType <DatabaseTable>());
            }
            var txt      = writer.Write(databaseTables);
            var fileName = writer.ContextName + ".cs";

            File.WriteAllText(
                Path.Combine(directory.FullName, fileName),
                txt);
            projectWriter.AddClass(fileName);
            return(writer.ContextName);
        }
Esempio n. 3
0
//#else
        public SchemaParameters(string connectionString, SqlType sqlType)
        {
            ConnectionString = connectionString;
            ProviderName     = ProviderToSqlType.Convert(sqlType);
            SqlType          = sqlType;
            Exclusions       = new Exclusions();
        }
        public void TestSqlTypeConstructor()
        {
            var schema = new DatabaseSchema(null, SqlType.SqlServer);

            //translated to correct provider name
            Assert.AreEqual("System.Data.SqlClient", schema.Provider);
            //it round trips back to SqlType
            Assert.AreEqual(SqlType.SqlServer, ProviderToSqlType.Convert(schema.Provider));

            //we'll check all the others in same test
            schema = new DatabaseSchema(null, SqlType.Oracle);
            Assert.AreEqual("System.Data.OracleClient", schema.Provider);
            Assert.AreEqual(SqlType.Oracle, ProviderToSqlType.Convert(schema.Provider));

            schema = new DatabaseSchema(null, SqlType.MySql);
            Assert.AreEqual("MySql.Data.MySqlClient", schema.Provider);
            Assert.AreEqual(SqlType.MySql, ProviderToSqlType.Convert(schema.Provider));

            schema = new DatabaseSchema(null, SqlType.SQLite);
            Assert.AreEqual("System.Data.SQLite", schema.Provider);
            Assert.AreEqual(SqlType.SQLite, ProviderToSqlType.Convert(schema.Provider));

            schema = new DatabaseSchema(null, SqlType.SqlServerCe);
            Assert.AreEqual("System.Data.SqlServerCe.4.0", schema.Provider);
            Assert.AreEqual(SqlType.SqlServerCe, ProviderToSqlType.Convert(schema.Provider));

            schema = new DatabaseSchema(null, SqlType.PostgreSql);
            Assert.AreEqual("Npgsql", schema.Provider);
            Assert.AreEqual(SqlType.PostgreSql, ProviderToSqlType.Convert(schema.Provider));

            schema = new DatabaseSchema(null, SqlType.Db2);
            Assert.AreEqual("IBM.Data.DB2", schema.Provider);
            Assert.AreEqual(SqlType.Db2, ProviderToSqlType.Convert(schema.Provider));
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseReader"/> class. For Oracle, use the overload.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="providerName">Name of the provider.</param>
        public DatabaseReader(string connectionString, string providerName)
        {
            _sr = new SchemaExtendedReader(connectionString, providerName);
            if (!string.IsNullOrEmpty(providerName))
            {
                var type = ProviderToSqlType.Convert(providerName);
                switch (type)
                {
                case SqlType.Oracle:
                    _sr = new OracleSchemaReader(connectionString, providerName);
                    break;

                case SqlType.SqlServer:
                    _sr = new SqlServerSchemaReader(connectionString, providerName);
                    break;

                case SqlType.SqlServerCe:
                    _sr = new SqlServerCeSchemaReader(connectionString, providerName);
                    break;

                case SqlType.MySql:
                    _sr = new MySqlSchemaReader(connectionString, providerName);
                    break;

                case SqlType.PostgreSql:
                    _sr = new PostgreSqlSchemaReader(connectionString, providerName);
                    break;

                case SqlType.Db2:
                    _sr = new Db2SchemaReader(connectionString, providerName);
                    break;
                }
                if (providerName.Equals("Ingres.Client", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new IngresSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("iAnyWhere.Data.SQLAnyWhere", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new SybaseAsaSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("Sybase.Data.AseClient", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new SybaseAseSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("iAnyWhere.Data.UltraLite", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new SybaseUltraLiteSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("System.Data.OleDb", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new OleDbSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("System.Data.VistaDB", StringComparison.OrdinalIgnoreCase))
                {
                    _sr = new VistaDbSchemaReader(connectionString, providerName);
                }
            }
            _db = new DatabaseSchema(connectionString, providerName);
        }
Esempio n. 6
0
//#if COREFX
        public SchemaParameters(System.Data.Common.DbConnection dbConnection)
        {
            DbConnection     = dbConnection;
            ProviderName     = DbConnection.GetType().Namespace;
            ConnectionString = dbConnection.ConnectionString;
            SqlType          = ProviderToSqlType.Convert(ProviderName);
            Exclusions       = new Exclusions();
        }
Esempio n. 7
0
        /// <summary>获取DatabaseTable
        ///
        /// </summary>
        /// <param name="strConnectionString">strConnectionString</param>
        /// <param name="sqlType">sqlType</param>
        /// <param name="strTableName">strTableName</param>
        /// <returns></returns>
        internal static DatabaseTable GetDatabaseTable(string strConnectionString,
                                                       SqlType sqlType,
                                                       string strTableName)
        {
            var rdr = new DatabaseReader(strConnectionString, ProviderToSqlType.Convert(sqlType));

            return(rdr.Table(strTableName));
        }
Esempio n. 8
0
        public TableGenerator(DatabaseTable table)
            : base(table)
        {
            SqlType?originSqlType = null;

            if (table.DatabaseSchema != null)
            {
                originSqlType = ProviderToSqlType.Convert(table.DatabaseSchema.Provider);
            }

            DataTypeWriter = new DataTypeWriter(originSqlType);
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcedureGenerator"/> class.
        /// </summary>
        /// <param name="table">The table.</param>
        public ProcedureGenerator(DatabaseTable table)
            : base(table)
        {
            SqlWriter = new SqlWriter(table, SqlType.SqlServer);
            SqlType?originSqlType = null;

            if (table.DatabaseSchema != null)
            {
                originSqlType = ProviderToSqlType.Convert(table.DatabaseSchema.Provider);
            }
            _dataTypeWriter = new DataTypeWriter(originSqlType);
        }
Esempio n. 10
0
        private void CodeGenFormLoad(object sender, EventArgs e)
        {
            var sqlType = ProviderToSqlType.Convert(_databaseSchema.Provider);

            if (sqlType.HasValue)
            {
                cmbDialect.SelectedItem = sqlType;
            }
            cmbProjectType.SelectedItem = DatabaseSchemaReader.CodeGen.CodeTarget.PocoNHibernateHbm;
            if (Properties.Settings.Default.CodeGenProjectType > 0)
            {
                cmbProjectType.SelectedIndex = Properties.Settings.Default.CodeGenProjectType;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Constructor with connectionString and ProviderName
        /// </summary>
        /// <param name="connectionString">Eg "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"</param>
        /// <param name="providerName">ProviderInvariantName for the provider (eg System.Data.SqlClient or System.Data.OracleClient)</param>
        public SchemaReader(string connectionString, string providerName)
        {
            if (String.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", "connectionString must not be empty");
            }

            if (String.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName", "providerName must not be empty");
            }

            ConnectionString = connectionString;
            ProviderName     = providerName;
            ProviderType     = ProviderToSqlType.Convert(providerName);
            Factory          = FactoryTools.GetFactory(ProviderName);
        }
Esempio n. 12
0
        /// <summary>
        /// Adds a dataType object to a column.
        /// </summary>
        /// <param name="column">The column.</param>
        public static void AddDataType(DatabaseColumn column)
        {
            if (column == null)
            {
                return;
            }
            //there is no data type at all
            if (string.IsNullOrEmpty(column.DbDataType))
            {
                return;
            }
            //a datatype already assigned
            if (column.DataType != null)
            {
                return;
            }
            //use upper case
            var dbType = column.DbDataType.ToUpperInvariant();

            //nothing to convert
            if (string.IsNullOrEmpty(dbType))
            {
                return;
            }
            var sqlType      = SqlType.SqlServer;
            var dataTypeList = new List <DataType>();

            if (column.Table != null)
            {
                //look up the full schema if it exists
                var schema = column.Table.DatabaseSchema;
                if (schema != null)
                {
                    var provider = schema.Provider;
                    sqlType      = ProviderToSqlType.Convert(provider) ?? SqlType.SqlServer;
                    dataTypeList = schema.DataTypes;
                }
            }
            //does the schema data types contain this type? if so, assign it.
            var dataType = FindDataType(dbType, dataTypeList, sqlType, column.Length);

            column.DataType = dataType;
        }
        public static DataTypeMapper DataTypeMapper(DatabaseTable databaseTable)
        {
            if (databaseTable == null)
            {
                throw new ArgumentNullException("databaseTable", "databaseTable must not be null");
            }
            var     schema = databaseTable.DatabaseSchema;
            SqlType?type   = SqlType.SqlServer;

            if (schema != null)
            {
                type = ProviderToSqlType.Convert(schema.Provider);
            }
            if (!type.HasValue)
            {
                type = SqlType.SqlServer;
            }
            return(DataTypeMapper(type.Value));
        }
Esempio n. 14
0
        private static SqlType?FindSqlType(DatabaseSchema databaseSchema)
        {
            var providerName = databaseSchema.Provider;

            return(ProviderToSqlType.Convert(providerName));
        }
Esempio n. 15
0
        private SqlType OriginSqlType()
        {
            var sqlType = ProviderToSqlType.Convert(_providerName);

            return(!sqlType.HasValue ? SqlType.SqlServer : sqlType.Value);
        }
Esempio n. 16
0
        public static SchemaExtendedReader Create(string connectionString, string providerName)
        {
            if (string.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName", "providerName must not be empty");
            }

            SchemaExtendedReader schemaReader = null;
            var type = ProviderToSqlType.Convert(providerName);

            switch (type)
            {
            case SqlType.Oracle:
                schemaReader = new OracleSchemaReader(connectionString, providerName);
                break;

            case SqlType.SqlServer:
                schemaReader = new SqlAzureOrSqlServerSchemaReader(connectionString, providerName);
                break;

            case SqlType.SqlServerCe:
                schemaReader = new SqlServerCeSchemaReader(connectionString, providerName);
                break;

            case SqlType.MySql:
                schemaReader = new MySqlSchemaReader(connectionString, providerName);
                break;

            case SqlType.PostgreSql:
                schemaReader = new PostgreSqlSchemaReader(connectionString, providerName);
                break;

            case SqlType.Db2:
                schemaReader = new Db2SchemaReader(connectionString, providerName);
                break;

            default:
                //all the other types
                if (providerName.Equals("Ingres.Client", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new IngresSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("iAnyWhere.Data.SQLAnyWhere", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new SybaseAsaSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("Sybase.Data.AseClient", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new SybaseAseSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("iAnyWhere.Data.UltraLite", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new SybaseUltraLiteSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("System.Data.OleDb", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new OleDbSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("System.Data.VistaDB", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new VistaDbSchemaReader(connectionString, providerName);
                }
                else if (providerName.Equals("IBM.Data.DB2.iSeries", StringComparison.OrdinalIgnoreCase))
                {
                    schemaReader = new Db2ISeriesSchemaReader(connectionString, providerName);
                }

                break;
            }
            if (schemaReader == null)
            {
                schemaReader = new SchemaExtendedReader(connectionString, providerName);
            }
            return(schemaReader);
        }
Esempio n. 17
0
 private SqlType FindSqlType()
 {
     var sqlType = ProviderToSqlType.Convert(_providerName);
     return !sqlType.HasValue ? SqlType.SqlServer : sqlType.Value;
 }
Esempio n. 18
0
        private static SqlType FindSqlType(string providerName)
        {
            var sqlType = ProviderToSqlType.Convert(providerName);

            return(!sqlType.HasValue ? SqlType.SqlServer : sqlType.Value);
        }
Esempio n. 19
0
        private SqlType FindSqlType()
        {
            var sqlType = ProviderToSqlType.Convert(_databaseSchema.Provider);

            return(!sqlType.HasValue ? SqlType.SqlServer : sqlType.Value);
        }