Beispiel #1
0
        /// <summary>
        /// Starts LiteDB database using a connection string for file system database
        /// </summary>
        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (connectionString.Upgrade == true)
            {
                // try upgrade if need
                LiteEngine.Upgrade(connectionString.Filename, connectionString.Password);
            }

            _engine         = connectionString.CreateEngine();
            _mapper         = mapper ?? BsonMapper.Global;
            _disposeOnClose = true;

            if (connectionString.Collation != null)
            {
                var current = this.Collation.ToString();

                if (connectionString.Collation.ToString() != current)
                {
                    this.Dispose();

                    throw new LiteException(0, $"Database collation '{current}' is different from connection string. Use Rebuild database to change collation.");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Starts LiteDB database using a connection string for file system database
        /// </summary>
        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (connectionString.Upgrade != UpgradeOption.False)
            {
                // try upgrade if need
                LiteEngine.Upgrade(connectionString.Filename, connectionString.Password, connectionString.Upgrade);
            }

            _engine = connectionString.CreateEngine();
            _mapper = mapper ?? BsonMapper.Global;
        }
Beispiel #3
0
        /// <summary>
        /// Starts LiteDB database using a connection string for file system database
        /// </summary>
        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (connectionString.Upgrade == true)
            {
                // try upgrade if need
                LiteEngine.Upgrade(connectionString.Filename, connectionString.Password, connectionString.Collation);
            }

            _engine         = connectionString.CreateEngine();
            _mapper         = mapper ?? BsonMapper.Global;
            _disposeOnClose = true;
        }