当前位置: 首页>>代码示例>>C#>>正文


C# DbContextOptionsBuilder.UseSqlite方法代码示例

本文整理汇总了C#中DbContextOptionsBuilder.UseSqlite方法的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptionsBuilder.UseSqlite方法的具体用法?C# DbContextOptionsBuilder.UseSqlite怎么用?C# DbContextOptionsBuilder.UseSqlite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbContextOptionsBuilder的用法示例。


在下文中一共展示了DbContextOptionsBuilder.UseSqlite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnConfiguring

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseSqlite($"Data Source={databaseFile};");
            optionsBuilder.EnableSensitiveDataLogging();
        }
开发者ID:kswoll,项目名称:restless,代码行数:7,代码来源:RestlessDb.cs

示例2: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     #if UNIT_TEST
     optionsBuilder.UseSqlite("Filename=PodcastsTests.db");
     #else
     optionsBuilder.UseSqlite("Filename=Podcasts.db");
     #endif
 }
开发者ID:Solocast,项目名称:solocast-clients,代码行数:8,代码来源:PodcastContext.cs

示例3: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     base.OnConfiguring(optionsBuilder);
     SqliteConnectionStringBuilder sb = new SqliteConnectionStringBuilder();
     sb.DataSource = filename;
     optionsBuilder.UseSqlite(sb.ToString());
 }
开发者ID:EppoFq,项目名称:AntShares,代码行数:7,代码来源:WalletDataContext.cs

示例4: It_enforces_foreign_key

        public void It_enforces_foreign_key(bool suppress)
        {
            var builder = new DbContextOptionsBuilder();
            var sqliteBuilder = builder.UseSqlite(_testStore.Connection.ConnectionString);
            if (suppress)
            {
                sqliteBuilder.SuppressForeignKeyEnforcement();
            }

            var options = builder.Options;

            using (var context = new MyContext(options))
            {
                context.Database.EnsureCreated();
                context.Add(new Child { ParentId = 4 });
                if (suppress)
                {
                    context.SaveChanges();
                }
                else
                {
                    var ex = Assert.Throws<DbUpdateException>(() => { context.SaveChanges(); });
                    Assert.Contains("FOREIGN KEY constraint failed", ex.InnerException.Message);
                }
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:26,代码来源:SqliteForeignKeyTest.cs

示例5: It_allows_foreign_key_to_unique_index

        public void It_allows_foreign_key_to_unique_index()
        {
            var builder = new DbContextOptionsBuilder();
            var sqliteBuilder = builder.UseSqlite(_testStore.Connection.ConnectionString);
            var options = builder.Options;
            _testStore.ExecuteNonQuery(@"
CREATE TABLE User (
    Id INTEGER PRIMARY KEY,
    AltId INTEGER NOT NULL UNIQUE
);
CREATE TABLE Comment (
    Id INTEGER PRIMARY KEY,
    UserAltId INTEGER NOT NULL,
    Comment TEXT,
    FOREIGN KEY (UserAltId) REFERENCES User (AltId)
);");

            long id;

            using (var context = new BloggingContext(options))
            {
                var entry = context.User.Add(new User { AltId = 1356524 });
                context.Comments.Add(new Comment { User = entry.Entity });
                context.SaveChanges();
                id = entry.Entity.Id;
            }

            using (var context = new BloggingContext(options))
            {
                var comment = context.Comments.Include(u => u.User).Single();
                Assert.Equal(id, comment.User.Id);
            }

        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:34,代码来源:SqliteForeignKeyTest.cs

示例6: Main

        public static void Main(string[] args)
        {
            Logger.Info("Update Batch Starting");

            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables();
            Configuration = builder.Build();

            DbContextOptionsBuilder<BddContext> options = new DbContextOptionsBuilder<BddContext>();
            options.UseSqlite(Program.Configuration["Data:DefaultConnection:ConnectionString"]);

            Options = options.Options;

            string[] equipe = new string[] { "equipe1", "equipe2", "equipe3"};

            // Parsing classement
            ParseClassement(equipe);

            // Parsing des actualités
            ParseActus();

            // Parsing des pages Agendas
            ParseAgendas();

            // Parsing des pages par journées
            ParseJournees();

            Logger.Info("Update Batch End");
        }
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:31,代码来源:Program.cs

示例7: OnConfiguring

 //Add-Migration vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
 //Update-Database vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
 protected override void OnConfiguring(DbContextOptionsBuilder options) {
   base.OnConfiguring(options);
   var config = ConfigurationManager.ConnectionStrings["Vyzva57-sqlite"];
   var conn = new SqliteConnection(config.ConnectionString);
   //var conn = new SqliteConnection("Data Source=" + MachinesLow.rootDir +  config.ConnectionString);
   options.UseSqlite(conn);
 }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:9,代码来源:Vyzva57Context.cs

示例8: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.IsConfigured)
     {
         optionsBuilder.UseSqlite("Filename=Notes.db");
     }
 }
开发者ID:rowanmiller,项目名称:Demo-EFCore,代码行数:7,代码来源:NoteContext.cs

示例9: InheritanceSqliteFixture

        public InheritanceSqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddSqlite()
                    .ServiceCollection()
                    .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                    .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                    .BuildServiceProvider();

            var testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseSqlite(testStore.Connection);
            _options = optionsBuilder.Options;

            // TODO: Do this via migrations & update pipeline

            testStore.ExecuteNonQuery(@"
                DROP TABLE IF EXISTS Country;
                DROP TABLE IF EXISTS Animal;

                CREATE TABLE Country (
                    Id int NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL
                );

                CREATE TABLE Animal (
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int NOT NULL ,
                    IsFlightless bit NOT NULL,
                    EagleId nvarchar(100),
                    'Group' int,
                    FoundOn tinyint,
                    Discriminator nvarchar(255),

                    FOREIGN KEY(countryId) REFERENCES Country(Id),
                    FOREIGN KEY(EagleId) REFERENCES Animal(Species)
                );

                CREATE TABLE Plant (
                    Genus int NOT NULL,
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int,
                    HasThorns bit,

                    FOREIGN KEY(countryId) REFERENCES Country(Id)
                );
            ");

            using (var context = CreateContext())
            {
                SeedData(context);
            }
            TestSqlLoggerFactory.Reset();
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:59,代码来源:InheritanceSqliteFixture.cs

示例10: OnConfiguring

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            spath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\" + "database.sqlite";

            optionsBuilder.UseSqlite("Data Source=" + spath);

            base.OnConfiguring(optionsBuilder);
        }
开发者ID:Prog-Maker,项目名称:SQLite_Identity20_EF7_MVC5,代码行数:8,代码来源:AppDbContext.cs

示例11: OnConfiguring

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder {DataSource = "test.db"};
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseSqlite(connection);
        }
开发者ID:cgideon,项目名称:CSharpSandbox,代码行数:8,代码来源:MyEntity.cs

示例12: EntitiesTests

        public EntitiesTests()
        {
            var builder = new DbContextOptionsBuilder();
            builder.UseSqlite($"Filename=DynamicLinqTestDb_{Guid.NewGuid()}.db");

            _context = new BlogContext(builder.Options);
            _context.Database.EnsureDeleted();
            _context.Database.EnsureCreated();
        }
开发者ID:StefH,项目名称:System.Linq.Dynamic,代码行数:9,代码来源:EntitiesTests.cs

示例13: OnConfiguring

        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);
        }
开发者ID:tchavdar,项目名称:MQTT-client,代码行数:9,代码来源:RawMQTTDataModel.cs

示例14: OnConfiguring

    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);
    }
开发者ID:lucaslra,项目名称:BAN5P,代码行数:9,代码来源:HqManagerDbContext.cs

示例15: Can_add_extension_with_ambient_transaction_warning_suppressed

        public void Can_add_extension_with_ambient_transaction_warning_suppressed()
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseSqlite("Database=Crunchie").SuppressAmbientTransactionWarning();

            var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();

            Assert.Equal(false, extension.ThrowOnAmbientTransaction);
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:9,代码来源:SqliteDbContextOptionsBuilderExtensionsTest.cs


注:本文中的DbContextOptionsBuilder.UseSqlite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。