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


C# DbContextOptionsBuilder类代码示例

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


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

示例1: OnConfiguring

 //Add-Migration lmcom-serv-001 -c NewData.NewLMComContext_SqlServer
 //Update-Database lmcom-serv-002 -c NewData.NewLMComContext_SqlServer
 protected override void OnConfiguring(DbContextOptionsBuilder options) {
   base.OnConfiguring(options);
   var config = ConfigurationManager.ConnectionStrings["Container"];
   var conn = new SqlConnection(config.ConnectionString);
   //var conn = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Initial Catalog=NewLMCom_ef7;Integrated Security=False;User ID=lmcomdatatest;Password=lmcomdatatest;");
   options.UseSqlServer(conn);
 }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:9,代码来源:NewLMComContext.cs

示例2: CreateStore

        private static IInMemoryDatabase CreateStore(IServiceProvider serviceProvider, bool persist)
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            return InMemoryTestHelpers.Instance.CreateContextServices(serviceProvider, optionsBuilder.Options).GetRequiredService<IInMemoryDatabase>();
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:7,代码来源:InMemoryDatabaseCreatorTest.cs

示例3: CreateContext

        public override CrossStoreContext CreateContext(TestStore testStore)
        {
            var inMemoryTestStore = testStore as InMemoryTestStore;
            if (inMemoryTestStore != null)
            {
                var optionsBuilder = new DbContextOptionsBuilder();
                optionsBuilder.UseInMemoryStore();

                return new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
            }

            var sqlServerTestStore = testStore as SqlServerTestStore;
            if (sqlServerTestStore != null)
            {
                var optionsBuilder = new DbContextOptionsBuilder();
                optionsBuilder.UseSqlServer(sqlServerTestStore.Connection);

                var context = new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
                context.Database.EnsureCreated();
                context.Database.AsRelational().Connection.UseTransaction(sqlServerTestStore.Transaction);

                return context;
            }

            throw new NotImplementedException();
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:26,代码来源:SharedCrossStoreFixture.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: Is_configured_when_configuration_contains_associated_extension

        public void Is_configured_when_configuration_contains_associated_extension()
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            Assert.True(new DatabaseProvider<InMemoryDatabaseProviderServices, InMemoryOptionsExtension>().IsConfigured(optionsBuilder.Options));
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:7,代码来源:InMemoryDatabaseProviderTest.cs

示例6: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     base.OnConfiguring(optionsBuilder);
     //var connectionString = @"Data Source=SERENITY\EXPRESS2014;Initial Catalog=TicketSystem;Integrated Security=True";
     var connectionString = @"Data Source=ENTERPRISE1\EXPRESS2014;Initial Catalog=code_louisville_dotnet;Integrated Security=True";
     optionsBuilder.UseSqlServer(connectionString);
 }
开发者ID:garrettld,项目名称:code_louisville_dotnet,代码行数:7,代码来源:TicketsDataContext.cs

示例7: OnConfiguring

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

            var connectionString = @"Server=(LocalDb)\MSSQLLocalDb;Database=AspNetBlog";
            optionsBuilder.UseSqlServer(connectionString);
        }
开发者ID:lukehammer,项目名称:AspNetBlog,代码行数:7,代码来源:BlogDataContext.cs

示例8: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     
     base.OnConfiguring(optionsBuilder);
     //optionsBuilder.Options.
     
 }
开发者ID:ReinhardHsu,项目名称:cloudscribe,代码行数:7,代码来源:CoreDbContext.cs

示例9: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder options)
 {
     var config = new Configuration()
         .AddJsonFile("config.json");
     var constr = config.Get("Data:DefaultConnection:ConnectionString");
     options.UseSqlServer(constr);
 }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:7,代码来源:ArtistContext.cs

示例10: 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

示例11: 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

示例12: OnConfiguring

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

            options.UseSqlServer("Server=(localdb)\\ProjectsV12;Database=EF7;Trusted_Connection=true;MultipleActiveResultSets=True").
                MaxBatchSize(20);
        }
开发者ID:tingvast,项目名称:EF7-Sandbox,代码行数:7,代码来源:EF7BloggContext.cs

示例13: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     #if DEBUG
     ConnectionString = "Server=(localdb)\\MSSQLLocalDB;Database=Health;Trusted_Connection=True;";
     #endif
     optionsBuilder.UseSqlServer(ConnectionString);
 }
开发者ID:Sharpiro,项目名称:Health,代码行数:7,代码来源:HealthContext.cs

示例14: 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

示例15: ConfigureServices

 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     string connectionString = @"Server= (localhost); Database =DESKTOP-S516B9C.CodeBlog;Trusted_Connection=True;";
     DbContextOptionsBuilder dbOpt = new DbContextOptionsBuilder<Context>();
     services.AddDbContext<Context>( options =>  options.UseSqlServer(connectionString));
     services.AddMvc();
 }
开发者ID:michaljaros84,项目名称:OneBigPlayground,代码行数:9,代码来源:Startup.cs


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