コード例 #1
0
ファイル: WalletDataContext.cs プロジェクト: EppoFq/AntShares
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     base.OnConfiguring(optionsBuilder);
     SqliteConnectionStringBuilder sb = new SqliteConnectionStringBuilder();
     sb.DataSource = filename;
     optionsBuilder.UseSqlite(sb.ToString());
 }
コード例 #2
0
 public SQLLiteTests() : base(new SqliteDialectProvider())
 {
     builder            = new SqliteConnectionStringBuilder();
     builder.DataSource = Path.Combine(Path.GetTempPath(), "test.db");
     builder.Mode       = SqliteOpenMode.ReadWriteCreate;
     builder.Cache      = SqliteCacheMode.Shared;
 }
        public void Ctor_parses_options()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            Assert.Equal("test.db", builder.DataSource);
            Assert.Equal(CacheMode.Private, builder.CacheMode);
        }
        public void Mode_works()
        {
            var builder = new SqliteConnectionStringBuilder();

            builder.Mode = SqliteOpenMode.Memory;

            Assert.Equal(SqliteOpenMode.Memory, builder.Mode);
        }
コード例 #5
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "WeatherDressing.db" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            //optionsBuilder.UseSqlite(connection);
        }
        public void DataSource_works()
        {
            var builder = new SqliteConnectionStringBuilder();

            builder.DataSource = "test.db";

            Assert.Equal("test.db", builder.DataSource);
        }
コード例 #7
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = DATABASE_NAME };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseSqlite(connection);
        }
コード例 #8
0
ファイル: Database.cs プロジェクト: WallyWest21/Notes-Manager
        // This method connects the context with the database
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "ef6NotesManagerV3.sqlite" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseSqlite(connection);
        }
コード例 #9
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "MQTTRawData.db" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);
            Debug.WriteLine($"Connecting to:{connection.ConnectionString}");

            optionsBuilder.UseSqlite(connection);
        }
コード例 #10
0
ファイル: HqManagerDbContext.cs プロジェクト: lucaslra/BAN5P
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
      var connStringBuilder = new SqliteConnectionStringBuilder
      { DataSource = Path.Combine(_appEnv.ApplicationBasePath, _data.Configuration["App:DbFile"]) };
      var connString = connStringBuilder.ToString();
      var conn = new SqliteConnection(connString);

      optionsBuilder.UseSqlite(conn);
    }
コード例 #11
0
ファイル: WpfClientContext.cs プロジェクト: Dki56t/MyNot
 public WpfClientContext()
     : base()
 {
     SqliteConnectionStringBuilder builder = new SqliteConnectionStringBuilder
     {
         DataSource = "tmp_localdb",
         Mode = SqliteOpenMode.ReadWriteCreate
     };
     _connectionString = builder.ConnectionString;
 }
コード例 #12
0
ファイル: FxContext.cs プロジェクト: ajr85/FxTesting
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // Visual Studio 2015 | Use the LocalDb 12 instance created by Visual Studio
            //optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;");

            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "test254.sqlite" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);
            
            optionsBuilder.UseSqlite(connection);
        }
コード例 #13
0
        /// <inheritDoc />
        protected override string BuildConnectionString(ReadOnlySpan <char> dsn, string user, string password, PhpArray options)
        {
            var csb = new ConnectionStringBuilder();

            csb.DataSource = dsn.ToString();
            csb.Add("Password", password);
            csb.Add("UserId", user);


            return(csb.ConnectionString);
        }
コード例 #14
0
        public override string ClassName()
        {
            var sqliteConnection = new SqliteConnectionStringBuilder(CustomConfiguration.ConnectionString);
            if (sqliteConnection.DataSource != null)
            {
                var fileName = Path.GetFileNameWithoutExtension(sqliteConnection.DataSource);
                return CSharpUtilities.GenerateCSharpIdentifier(
                    fileName + DbContextSuffix, null);
            }

            return base.ClassName();
        }
コード例 #15
0
        public SqliteDatabaseProvider()
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            var builder = new DbContextOptionsBuilder<TestDbContext>();
            builder.UseSqlite(connection);
            options = builder.Options;

            using (var context = new TestDbContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();
            }
        }
コード例 #16
0
        /// <summary>
        ///     Loads an MBBSEmu representation of a Btrieve File from the specified Sqlite DB file.
        /// </summary>
        private void LoadSqlite(string fullPath)
        {
            _logger.Info($"Opening sqlite DB {fullPath}");

            FullPath = fullPath;

            var connectionString = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder()
            {
                Mode       = Microsoft.Data.Sqlite.SqliteOpenMode.ReadWriteCreate,
                DataSource = fullPath,
            }.ToString();

            _connection = new SqliteConnection(connectionString);
            _connection.Open();

            LoadSqliteMetadata();
        }
コード例 #17
0
ファイル: StorageContext.cs プロジェクト: TheRealVira/Scrooge
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var loggingService = Singleton<ServiceController>.Instance.Get<ILoggingService>();
            loggingService.WriteLine("Configuring database connection...");

            var connectionStringBuilder = new SqliteConnectionStringBuilder {DataSource = "scrooge.db"};
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            loggingService.WriteLine("Using connection string: " + connectionString);

            optionsBuilder.UseSqlite(connection);

            base.OnConfiguring(optionsBuilder);

            loggingService.WriteLine("Database configured!");
        }
コード例 #18
0
        public void Ctor_parses_Password()
        {
            var builder = new SqliteConnectionStringBuilder("Password=key");

            Assert.Equal("key", builder.Password);
        }
コード例 #19
0
        public void Ctor_parses_DataSource(string keyword)
        {
            var builder = new SqliteConnectionStringBuilder($"{keyword}=test.db");

            Assert.Equal("test.db", builder.DataSource);
        }
コード例 #20
0
        public void Item_throws_when_cannot_convert_to_bool_on_set(object value)
        {
            var builder = new SqliteConnectionStringBuilder();

            Assert.ThrowsAny <FormatException>(() => builder["Foreign Keys"] = value);
        }
        public void Clear_resets_everything()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db;Mode=Memory;Cache=Shared");

            builder.Clear();

            Assert.Empty(builder.DataSource);
            Assert.Equal(SqliteOpenMode.ReadWriteCreate, builder.Mode);
            Assert.Equal(SqliteCacheMode.Default, builder.Cache);
        }
 public void Filename_is_alias_for_DataSource()
 {
     var builder = new SqliteConnectionStringBuilder("Filename=inline.db");
     Assert.Equal("inline.db", builder.DataSource);
 }
コード例 #23
0
        public void Ctor_parses_DefaultTimeout(string keyword)
        {
            var builder = new SqliteConnectionStringBuilder($"{keyword}=1");

            Assert.Equal(1, builder.DefaultTimeout);
        }
        public void Clear_resets_everything()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            builder.Clear();

            Assert.Empty(builder.DataSource);
        }
 public void It_takes_last_alias_specified()
 {
     var builder = new SqliteConnectionStringBuilder("Filename=ignore me.db; Data Source=and me too.db; DataSource=this_one.db");
     
     Assert.Equal("this_one.db", builder.DataSource);
 }
        public void ToString_builds_string()
        {
            var builder = new SqliteConnectionStringBuilder
            {
                DataSource = "test.db",
                Cache = SqliteCacheMode.Shared,
                Mode = SqliteOpenMode.Memory
            };

            Assert.Equal("Data Source=test.db;Mode=Memory;Cache=Shared", builder.ToString());
        }
コード例 #27
0
        public void Filename_is_alias_for_DataSource()
        {
            var builder = new SqliteConnectionStringBuilder("Filename=inline.db");

            Assert.Equal("inline.db", builder.DataSource);
        }
コード例 #28
0
        public void FullySetupRelationshipsTest(DatabaseType databaseType)
        {
            // Arrange
            // Create untracked entities equivaelent to our collection
            // and then attempt to save and check list
            var childEntities = new List<ChildEntity>
                {
                    new ChildEntity {Id = 1, Name = "ChildEntity 1", ParentEntityId = 1},
                    new ChildEntity {Id = default(long), Name = "ChildEntity 3", ParentEntityId = 1}
                };

            var childEntityReferencingChildEntities = new List<ChildEntityReferencingChildEntity>
                {
                    new ChildEntityReferencingChildEntity
                    {
                        Id = 1,
                        Name = "ChildEntityReferencingChildEntity 1",
                        ChildEntityId = 1,
                        ChildEntity = childEntities.Single(x => x.Id == 1),
                        ParentEntityId = 1
                    },
                    new ChildEntityReferencingChildEntity
                    {
                        Id = default(long),
                        Name = "ChildEntityReferencingChildEntity 3",
                        ChildEntityId = default(long),
                        ChildEntity = childEntities.Last(), // untracked and not yet added
                        ParentEntityId = 1
                    }
                };

            // If this relationship is already established then the entities must be added
            childEntities.First().ChildEntityReferencingChildEntities =
                childEntityReferencingChildEntities.Where(x => x.ChildEntityId == 1).ToList();

            // GraphDiff cannot handle this situation where a collection is added
            // Must have an existing Id or else EF fails.
            //childEntities.Last().ChildEntityReferencingChildEntities =
            //    childEntityReferencingChildEntities.Where(x => x.ChildEntityId == default(long)).ToList();

            var parentEntity = new ParentEntity
            {
                Id = 1,
                Name = "ParentEntity 1",
                ChildEntities = childEntities.Where(x => x.ParentEntityId == 1).ToList(),
                ChildReferencingChildEntities =
                    childEntityReferencingChildEntities.Where(x => x.ParentEntityId == 1).ToList()
            };

            // act
            var optionsBuilder = new DbContextOptionsBuilder<SimpleContext>();
            switch (databaseType)
            {
                case DatabaseType.InMemory:
                    optionsBuilder.UseInMemoryDatabase();
                    break;
                case DatabaseType.Sqlite:
                    var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "test.db" };
                    var connectionString = connectionStringBuilder.ToString();
                    var connection = new SqliteConnection(connectionString);
                    optionsBuilder.UseSqlite(connection);

                    // Need to load in the Sqlite assemblies - overload assembly resolver
                    // http://stackoverflow.com/questions/7264383/options-for-using-system-data-sqlite-in-a-32bit-and-64bit-c-sharp-world
                    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
                    {
                        if (args.Name == "Sqlite3")
                        {
                            var path = Path.Combine(@"..\..\..\Lib\Sqlite3\", "Native");
                            path = Path.Combine(path, Environment.Is64BitProcess ? @"x64\" : @"x32\");
                            path = Path.Combine(path, "Sqlite3.dll");
                            return Assembly.LoadFrom(path);
                        }
                        return null;
                    };
                    break;

                case DatabaseType.SqlServer:
                    optionsBuilder.UseSqlServer(@"Server=(LocalDB)\MSSQLLocalDB;Database=Test;integrated security=True;");
                    break;
            }

            using (var context = new SimpleContext(optionsBuilder.Options))
            {
                // To ensure contents are empty delete contents for Sqlite
                context.Database.EnsureDeleted();

                // Ensure DB created
                context.Database.EnsureCreated();

                SimpleInitializer.Seed(context);
            } // must be seeded with a separate context or already added to graph

            using (var context = new SimpleContext(optionsBuilder.Options))
            {
                context.Update(parentEntity);

                context.SaveChanges();
            }

            // assert
            using (var context = new SimpleContext(optionsBuilder.Options))
            {
                var persistedParentEntity =
                    context.ParentEntities
                        .Include(x => x.ChildEntities)
                        .Include(x => x.ChildReferencingChildEntities)
                        .Single(x => x.Id == parentEntity.Id);

                Assert.That(persistedParentEntity.Id, Is.EqualTo(parentEntity.Id));
                Assert.That(persistedParentEntity.Name, Is.EqualTo(parentEntity.Name));
                Assert.That(persistedParentEntity.ChildEntities.Count, Is.EqualTo(parentEntity.ChildEntities.Count));
                Assert.That(persistedParentEntity.ChildReferencingChildEntities.Count,
                    Is.EqualTo(parentEntity.ChildReferencingChildEntities.Count));

                // Require to order by as EF 7 orders in the opposite order
                var zippedChildren =
                    persistedParentEntity.ChildEntities.OrderBy(x => x.Id).Zip(parentEntity.ChildEntities,
                        (persisted, entity) => new {Persisted = persisted, Entity = entity});

                foreach (var persistedAndEntity in zippedChildren)
                {
                    Assert.That(persistedAndEntity.Persisted.Name, Is.EqualTo(persistedAndEntity.Entity.Name));
                    Assert.That(persistedAndEntity.Persisted.ParentEntityId, Is.EqualTo(persistedAndEntity.Entity.ParentEntityId));
                }

                var zippedChildReferencingChildren =
                    persistedParentEntity.ChildReferencingChildEntities.OrderBy(x => x.Id).Zip(
                        parentEntity.ChildReferencingChildEntities,
                        (persisted, entity) => new {Persisted = persisted, Entity = entity});

                foreach (var persistedAndEntity in zippedChildReferencingChildren)
                {
                    Assert.That(persistedAndEntity.Persisted.Name, Is.EqualTo(persistedAndEntity.Entity.Name));
                    Assert.That(persistedAndEntity.Persisted.ParentEntityId, Is.EqualTo(persistedAndEntity.Entity.ParentEntityId));
                    Assert.That(persistedAndEntity.Persisted.ChildEntityId, Is.EqualTo(
                            persistedAndEntity.Entity.ChildEntityId == default(long) ?
                                3 : persistedAndEntity.Entity.ChildEntityId)); // should be added following ef graph merge
                }
            }
        }
        public void Ctor_parses_mode()
        {
            var builder = new SqliteConnectionStringBuilder("Mode=Memory");

            Assert.Equal(SqliteOpenMode.Memory, builder.Mode);
        }
        public void Ctor_parses_options()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            Assert.Equal("test.db", builder.DataSource);
        }
        public void ToString_builds_minimal_string()
        {
            var builder = new SqliteConnectionStringBuilder
            {
                DataSource = "test.db"
            };

            Assert.Equal("Data Source=test.db", builder.ToString());
        }
コード例 #32
0
        public void Ctor_parses_ForeignKeys()
        {
            var builder = new SqliteConnectionStringBuilder("Foreign Keys=True");

            Assert.True(builder.ForeignKeys);
        }
        public void Item_resets_value_when_null()
        {
            var builder = new SqliteConnectionStringBuilder();
            builder.DataSource = "test.db";

            builder["Data Source"] = null;

            Assert.Empty(builder.DataSource);
        }
コード例 #34
0
        public void Ctor_parses_RecursiveTriggers()
        {
            var builder = new SqliteConnectionStringBuilder("Recursive Triggers=True");

            Assert.True(builder.RecursiveTriggers);
        }
        public void Item_gets_value()
        {
            var builder = new SqliteConnectionStringBuilder();
            builder.DataSource = "test.db";

            Assert.Equal("test.db", builder["Data Source"]);
        }
コード例 #36
0
        public void ConnectionString_defaults_to_empty()
        {
            var builder = new SqliteConnectionStringBuilder();

            Assert.Empty(builder.ConnectionString);
        }
        public void Ctor_parses_mode()
        {
            var builder = new SqliteConnectionStringBuilder("Mode=Memory");

            Assert.Equal(SqliteOpenMode.Memory, builder.Mode);
        }
        public void ToString_builds_string()
        {
            var builder = new SqliteConnectionStringBuilder
                {
                    DataSource = "test.db",
                    CacheMode = CacheMode.Shared
                };
            Assert.Equal("Data Source=test.db;Cache=Shared", builder.ToString());

            Assert.Equal("Data Source=test2.db", new SqliteConnectionStringBuilder(" Data Source = test2.db ").ToString());
        }
コード例 #39
0
        public void Ctor_parses_LowerCaseGuids()
        {
            var builder = new SqliteConnectionStringBuilder("Lower Case Guids = True");

            Assert.True(builder.LowerCaseGuids);
        }
コード例 #40
0
        public virtual SqliteRelationalConnection CreateReadOnlyConnection()
        {
            var builder = new SqliteConnectionStringBuilder(ConnectionString)
            {
                Mode = SqliteOpenMode.ReadOnly
            };

            var options = new DbContextOptionsBuilder();
            options.UseSqlite(builder.ToString());

            return new SqliteRelationalConnection(
                _rawSqlCommandBuilder,
                options.Options,
                (ILogger<SqliteRelationalConnection>)Logger);
        }
        public void Remove_resets_option()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            var removed = builder.Remove("Data Source");

            Assert.True(removed);
            Assert.Empty(builder.DataSource);
        }
        public void Item_throws_when_cannot_convert_to_enum_on_set(object value)
        {
            var builder = new SqliteConnectionStringBuilder();

            Assert.ThrowsAny <ArgumentException>(() => builder["Cache"] = value);
        }
        public void ShouldSerialize_returns_true_when_set()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            Assert.True(builder.ShouldSerialize("Data Source"));
        }
コード例 #44
0
        public void ShouldSerialize_returns_true_when_set()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            Assert.True(builder.ShouldSerialize("Data Source"));
        }
        public void TryGetValue_returns_false_when_not_exists()
        {
            object value;
            var retrieved = new SqliteConnectionStringBuilder().TryGetValue("Invalid", out value);

            Assert.False(retrieved);
            Assert.Null(value);
        }
コード例 #46
0
        public void It_takes_last_alias_specified()
        {
            var builder = new SqliteConnectionStringBuilder("Filename=ignore me.db; Data Source=and me too.db; DataSource=this_one.db");

            Assert.Equal("this_one.db", builder.DataSource);
        }
        public void TryGetValue_returns_true_when_exists()
        {
            var builder = new SqliteConnectionStringBuilder("Data Source=test.db");

            object value;
            var retrieved = builder.TryGetValue("Data Source", out value);

            Assert.True(retrieved);
            Assert.Equal("test.db", value);
        }