示例#1
0
        public Database(Configuration configuration)
        {
            this.objectFactory = configuration.ObjectFactory;
            if (!this.objectFactory.MetaPopulation.IsValid)
            {
                throw new ArgumentException("Domain is invalid");
            }

            this.concreteClassesByObjectType = new Dictionary<IObjectType, object>();

            this.connectionString = configuration.ConnectionString;
            this.commandTimeout = configuration.CommandTimeout;
            this.isolationLevel = configuration.IsolationLevel;

            this.sortedUnitRolesByObjectType = new Dictionary<IObjectType, IRoleType[]>();

            this.cache = configuration.CacheFactory.CreateCache(this);

            var connectionStringBuilder = new SqlConnectionStringBuilder(this.ConnectionString);
            var applicationName = connectionStringBuilder.ApplicationName.Trim();
            if (!string.IsNullOrWhiteSpace(applicationName))
            {
                this.id = applicationName;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                {
                    this.id = connectionStringBuilder.InitialCatalog.ToLowerInvariant();
                }
                else
                {
                    using (var connection = new SqlConnection(this.ConnectionString))
                    {
                        connection.Open();
                        this.id = connection.Database.ToLowerInvariant();
                    }
                }
            }

            this.schemaName = (configuration.SchemaName ?? "allors").ToLowerInvariant();
            this.objectIds = configuration.ObjectIds ?? new ObjectIdsInteger();
        }
示例#2
0
        public Database(Configuration configuration)
        {
            this.connectionString = configuration.ConnectionString;
            if (this.connectionString == null)
            {
                throw new Exception("Configuration.ConnectionString is missing");
            }

            var connectionStringBuilder = new SqlConnectionStringBuilder(this.connectionString);
            var applicationName = connectionStringBuilder.ApplicationName.Trim();
            if (!string.IsNullOrWhiteSpace(applicationName))
            {
                this.id = applicationName;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                {
                    this.id = connectionStringBuilder.InitialCatalog.ToLowerInvariant();
                }
                else
                {
                    using (this.connection = new SqlConnection(this.connectionString))
                    {
                        this.connection.Open();
                        this.id = this.connection.Database.ToLowerInvariant();
                    }
                }
            }

            this.objectFactory = configuration.ObjectFactory;
            if (this.objectFactory == null)
            {
                throw new Exception("Configuration.ObjectFactory is missing");
            }

            if (!this.objectFactory.MetaPopulation.IsValid)
            {
                throw new ArgumentException("Domain is invalid");
            }

            this.objectIds = configuration.ObjectIds ?? new ObjectIdsInteger();
            this.roleCache = configuration.RoleCache ?? new RoleCache();
            this.classCache = configuration.ClassCache ?? new ClassCache();
            this.commandTimeout = configuration.CommandTimeout ?? 30;
            this.isolationLevel = configuration.IsolationLevel ?? IsolationLevel.Snapshot;
            this.schemaName = configuration.SchemaName ?? "allors";
            this.useViews = configuration.UseViews ?? true;

            if (this.ObjectIds is ObjectIdsInteger)
            {
                this.mapping = new MappingInteger(this);
            }
            else if (this.ObjectIds is ObjectIdsLong)
            {
                this.mapping = new MappingLong(this);
            }
            else
            {
                throw new NotSupportedException("ObjectIds of type " + this.ObjectIds.GetType() + " are not supported.");
            }
        }