상속: Shaolinq.Persistence.SqlDatabaseContextInfo
예제 #1
0
        public static SqlServerSqlDatabaseContext Create(SqlServerSqlDatabaseContextInfo contextInfo, DataAccessModel model)
        {
            var constraintDefaults       = model.Configuration.ConstraintDefaults;
            var sqlDataTypeProvider      = new SqlServerSqlDataTypeProvider(constraintDefaults);
            var sqlQueryFormatterManager = new DefaultSqlQueryFormatterManager(SqlServerSqlDialect.Default, sqlDataTypeProvider, typeof(SqlServerSqlQueryFormatter));

            return(new SqlServerSqlDatabaseContext(model, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo));
        }
예제 #2
0
		internal SqlServerSqlDialect(SqlServerSqlDatabaseContextInfo contextInfo)
		{
			if (contextInfo != null)
			{
				var connectionString = contextInfo.ConnectionString;
				var marsEnabledInConnectionString = connectionString != null && Regex.IsMatch(connectionString, @".*MultipleActiveResultSets\s*=\s*true.*", RegexOptions.IgnoreCase);

				marsEnabled = contextInfo.MultipleActiveResultSets || marsEnabledInConnectionString;
			}
		}
예제 #3
0
        internal SqlServerSqlDialect(SqlServerSqlDatabaseContextInfo contextInfo)
        {
            if (contextInfo != null)
            {
                var connectionString = contextInfo.ConnectionString;
                var marsEnabledInConnectionString = connectionString != null && Regex.IsMatch(connectionString, @".*MultipleActiveResultSets\s*=\s*true.*", RegexOptions.IgnoreCase);

                this.marsEnabled = contextInfo.MultipleActiveResultSets || marsEnabledInConnectionString;
            }
        }
		public static SqlServerSqlDatabaseContext Create(SqlServerSqlDatabaseContextInfo contextInfo, DataAccessModel model)
		{
			var constraintDefaults = model.Configuration.ConstraintDefaultsConfiguration;
			var sqlDataTypeProvider = new SqlServerSqlDataTypeProvider(constraintDefaults);
			var sqlDialect = new SqlServerSqlDialect(contextInfo);
			var typeDescriptorProvider = model.TypeDescriptorProvider;
			var sqlQueryFormatterManager = new DefaultSqlQueryFormatterManager(sqlDialect, options => new SqlServerSqlQueryFormatter(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider));

			return new SqlServerSqlDatabaseContext(model, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo);
		}
예제 #5
0
        public static SqlServerSqlDatabaseContext Create(SqlServerSqlDatabaseContextInfo contextInfo, DataAccessModel model)
        {
            var constraintDefaults       = model.Configuration.ConstraintDefaultsConfiguration;
            var sqlDataTypeProvider      = CreateSqlDataTypeProvider(model, contextInfo, () => new SqlServerSqlDataTypeProvider(constraintDefaults));
            var sqlDialect               = new SqlServerSqlDialect(contextInfo);
            var typeDescriptorProvider   = model.TypeDescriptorProvider;
            var sqlQueryFormatterManager = new DefaultSqlQueryFormatterManager(sqlDialect, model.Configuration.NamingTransforms, (options, connection) => new SqlServerSqlQueryFormatter(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider, contextInfo, ((SqlConnection)connection)?.ServerVersion));

            return(new SqlServerSqlDatabaseContext(model, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo));
        }
        public static SqlServerSqlDatabaseContext Create(SqlServerSqlDatabaseContextInfo contextInfo, DataAccessModel model)
        {
            var constraintDefaults       = model.Configuration.ConstraintDefaultsConfiguration;
            var sqlDataTypeProvider      = new SqlServerSqlDataTypeProvider(constraintDefaults);
            var sqlDialect               = new SqlServerSqlDialect(contextInfo);
            var typeDescriptorProvider   = model.TypeDescriptorProvider;
            var sqlQueryFormatterManager = new DefaultSqlQueryFormatterManager(sqlDialect, options => new SqlServerSqlQueryFormatter(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider));

            return(new SqlServerSqlDatabaseContext(model, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo));
        }
		private static string GetDatabaseName(SqlServerSqlDatabaseContextInfo contextInfo)
		{
			if (string.IsNullOrEmpty(contextInfo.ConnectionString))
			{
				return contextInfo.DatabaseName;
			}

			var match = DatabaseRegex.Match(contextInfo.ConnectionString);

			if (match.Success)
			{
				return match.Groups[1].Value;
			}

			return string.Empty;
		}
예제 #8
0
        private static string GetDatabaseName(SqlServerSqlDatabaseContextInfo contextInfo)
        {
            if (string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                return(contextInfo.DatabaseName);
            }

            var match = DatabaseRegex.Match(contextInfo.ConnectionString);

            if (match.Success)
            {
                return(match.Groups[1].Value);
            }

            return(string.Empty);
        }
예제 #9
0
        private SqlServerSqlDatabaseContext(DataAccessModel model, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, SqlServerSqlDatabaseContextInfo contextInfo)
            : base(model, SqlServerSqlDialect.Default, sqlDataTypeProvider, sqlQueryFormatterManager, GetDatabaseName(contextInfo).Trim(), contextInfo)
        {
            this.ServerName = contextInfo.ServerName;
            this.Username = contextInfo.UserName;
            this.Password = contextInfo.Password;
            this.Instance = contextInfo.Instance;
            this.DeleteDatabaseDropsTablesOnly = contextInfo.DeleteDatabaseDropsTablesOnly;

            if (!string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                var found = false;

                this.ConnectionString = contextInfo.ConnectionString;

                this.ConnectionString = Regex.Replace(this.ConnectionString, @"Enlist\s*=[^;$]+", c =>
                {
                    found = true;

                    return "Enlist=False";
                });

                if (!found)
                {
                    this.ConnectionString += ";Enlist=False;";
                }

                this.ServerConnectionString = ConnectionStringDatabaseNameRegex.Replace(this.ConnectionString, "Initial Catalog=master;");
            }
            else
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder();

                var dataSource = this.ServerName;

                if (!string.IsNullOrEmpty(this.Instance))
                {
                    dataSource += @"\" + this.Instance;
                }

                if (string.IsNullOrEmpty(this.Username) || contextInfo.TrustedConnection)
                {
                    connectionStringBuilder.IntegratedSecurity = true;
                }
                else
                {
                    connectionStringBuilder.UserID = this.Username;
                    connectionStringBuilder.Password = this.Password;
                }

                connectionStringBuilder.Enlist = false;
                connectionStringBuilder.DataSource = dataSource;
                connectionStringBuilder.InitialCatalog = this.DatabaseName;
                connectionStringBuilder.Encrypt = contextInfo.Encrypt;

                if (contextInfo.ConnectionTimeout != null)
                {
                    connectionStringBuilder.ConnectTimeout = contextInfo.ConnectionTimeout.Value;
                }

                this.ConnectionString = connectionStringBuilder.ConnectionString;
                connectionStringBuilder.InitialCatalog = "master";
                this.ServerConnectionString = connectionStringBuilder.ConnectionString;
            }

            this.SchemaManager = new SqlServerSqlDatabaseSchemaManager(this);
        }
예제 #10
0
        public static SqlServerSqlDatabaseContext Create(SqlServerSqlDatabaseContextInfo contextInfo, DataAccessModel model)
        {
            var constraintDefaults = model.Configuration.ConstraintDefaults;
            var sqlDataTypeProvider = new SqlServerSqlDataTypeProvider(constraintDefaults);
            var sqlQueryFormatterManager = new DefaultSqlQueryFormatterManager(SqlServerSqlDialect.Default, sqlDataTypeProvider, typeof(SqlServerSqlQueryFormatter));

            return new SqlServerSqlDatabaseContext(model, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo);
        }
 public SqlServerSqlQueryFormatter(SqlQueryFormatterOptions options, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, TypeDescriptorProvider typeDescriptorProvider, SqlServerSqlDatabaseContextInfo contextInfo, string serverVersion)
     : base(options, sqlDialect, sqlDataTypeProvider, typeDescriptorProvider)
 {
     this.contextInfo  = contextInfo;
     this.majorVersion = serverVersion == null ? null : (int?)Convert.ToInt32(serverVersion.Split('.')[0]);
 }
예제 #12
0
        private SqlServerSqlDatabaseContext(DataAccessModel model, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, SqlServerSqlDatabaseContextInfo contextInfo)
            : base(model, new SqlServerSqlDialect(contextInfo), sqlDataTypeProvider, sqlQueryFormatterManager, GetDatabaseName(contextInfo).Trim(), contextInfo)
        {
            this.ServerName                    = contextInfo.ServerName;
            this.Username                      = contextInfo.UserName;
            this.Password                      = contextInfo.Password;
            this.Instance                      = contextInfo.Instance;
            this.AllowSnapshotIsolation        = contextInfo.AllowSnapshotIsolation;
            this.ReadCommittedSnapshot         = contextInfo.ReadCommittedSnapshot;
            this.DeleteDatabaseDropsTablesOnly = contextInfo.DeleteDatabaseDropsTablesOnly;

            if (!string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                var found = false;

                this.ConnectionString = contextInfo.ConnectionString;

                this.ConnectionString = EnlistRegex.Replace(this.ConnectionString, c =>
                {
                    found = true;

                    return(IsRunningMono() ? "" : "Enlist=False");
                });

                if (!found && !IsRunningMono())
                {
                    this.ConnectionString += ";Enlist=False;";
                }

                this.ServerConnectionString = DatabaseRegex.Replace(this.ConnectionString, "Initial Catalog=master;");
            }
            else
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder();

                var dataSource = this.ServerName;

                if (!string.IsNullOrEmpty(this.Instance))
                {
                    dataSource += @"\" + this.Instance;
                }

                if (string.IsNullOrEmpty(this.Username) || contextInfo.TrustedConnection)
                {
                    connectionStringBuilder.IntegratedSecurity = true;
                }
                else
                {
                    connectionStringBuilder.UserID   = this.Username;
                    connectionStringBuilder.Password = this.Password;
                }

                connectionStringBuilder.MultipleActiveResultSets = contextInfo.MultipleActiveResultSets;

                if (!IsRunningMono())
                {
                    connectionStringBuilder.Enlist = false;
                }

                connectionStringBuilder.DataSource     = dataSource;
                connectionStringBuilder.InitialCatalog = this.DatabaseName;
                connectionStringBuilder.Encrypt        = contextInfo.Encrypt;
                connectionStringBuilder.Pooling        = contextInfo.Pooling;

                // TODO: Remove when Mono switches to using reference source implementation

                if (!IsRunningMono())
                {
                    connectionStringBuilder.TypeSystemVersion = contextInfo.TypeSystemVersion ?? "SQL Server 2008";
                }

                if (contextInfo.ConnectionTimeout != null)
                {
                    connectionStringBuilder.ConnectTimeout = contextInfo.ConnectionTimeout.Value;
                }

                this.ConnectionString = connectionStringBuilder.ConnectionString;
                connectionStringBuilder.InitialCatalog = "master";
                this.ServerConnectionString            = connectionStringBuilder.ConnectionString;
            }

            this.SchemaManager = new SqlServerSqlDatabaseSchemaManager(this);
        }
예제 #13
0
        private SqlServerSqlDatabaseContext(DataAccessModel model, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, SqlServerSqlDatabaseContextInfo contextInfo)
            : base(model, SqlServerSqlDialect.Default, sqlDataTypeProvider, sqlQueryFormatterManager, GetDatabaseName(contextInfo).Trim(), contextInfo)
        {
            this.ServerName = contextInfo.ServerName;
            this.Username   = contextInfo.UserName;
            this.Password   = contextInfo.Password;
            this.Instance   = contextInfo.Instance;
            this.DeleteDatabaseDropsTablesOnly = contextInfo.DeleteDatabaseDropsTablesOnly;

            if (!string.IsNullOrEmpty(contextInfo.ConnectionString))
            {
                var found = false;

                this.ConnectionString = contextInfo.ConnectionString;

                this.ConnectionString = Regex.Replace(this.ConnectionString, @"Enlist\s*=[^;$]+", c =>
                {
                    found = true;

                    return("Enlist=False");
                });

                if (!found)
                {
                    this.ConnectionString += ";Enlist=False;";
                }

                this.ServerConnectionString = ConnectionStringDatabaseNameRegex.Replace(this.ConnectionString, "Initial Catalog=master;");
            }
            else
            {
                var connectionStringBuilder = new SqlConnectionStringBuilder();

                var dataSource = this.ServerName;

                if (!string.IsNullOrEmpty(this.Instance))
                {
                    dataSource += @"\" + this.Instance;
                }

                if (string.IsNullOrEmpty(this.Username) || contextInfo.TrustedConnection)
                {
                    connectionStringBuilder.IntegratedSecurity = true;
                }
                else
                {
                    connectionStringBuilder.UserID   = this.Username;
                    connectionStringBuilder.Password = this.Password;
                }

                connectionStringBuilder.Enlist         = false;
                connectionStringBuilder.DataSource     = dataSource;
                connectionStringBuilder.InitialCatalog = this.DatabaseName;
                connectionStringBuilder.Encrypt        = contextInfo.Encrypt;

                if (contextInfo.ConnectionTimeout != null)
                {
                    connectionStringBuilder.ConnectTimeout = contextInfo.ConnectionTimeout.Value;
                }

                this.ConnectionString = connectionStringBuilder.ConnectionString;
                connectionStringBuilder.InitialCatalog = "master";
                this.ServerConnectionString            = connectionStringBuilder.ConnectionString;
            }

            this.SchemaManager = new SqlServerSqlDatabaseSchemaManager(this);
        }