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


C# DbContextOptions.UseSqlServer方法代码示例

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


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

示例1: UseSqlServer_throws_if_options_are_locked

        public void UseSqlServer_throws_if_options_are_locked()
        {
            var options = new DbContextOptions<DbContext>();
            options.Lock();

            Assert.Equal(
                GetString("FormatEntityConfigurationLocked", "UseSqlServer"),
                Assert.Throws<InvalidOperationException>(() => options.UseSqlServer("Database=DoubleDecker")).Message);

            Assert.Equal(
                GetString("FormatEntityConfigurationLocked", "UseSqlServer"),
                Assert.Throws<InvalidOperationException>(() => options.UseSqlServer(new SqlConnection())).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:SqlServerDbContextOptionsExtensionsTest.cs

示例2: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     if (!options.IsAlreadyConfigured())
     {
         options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
     }
 }
开发者ID:rowanmiller,项目名称:Demo-EF7,代码行数:7,代码来源:CycleSalesContext.cs

示例3: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     // TODO: This check is so that we can pass in external options from tests
     //       Need to come up with a better way to handle this scenario
     if (!((IDbContextOptionsExtensions)options).Extensions.Any())
     {
         // TODO: Connection string in code rather than config file because of temporary limitation with Migrations
         options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
     }
 }
开发者ID:rowanmiller,项目名称:Demo-EF7,代码行数:10,代码来源:CycleSalesContext.cs

示例4: Can_add_extension_with_connection_string_using_generic_options

        public void Can_add_extension_with_connection_string_using_generic_options()
        {
            var options = new DbContextOptions<DbContext>();

            options = options.UseSqlServer("Database=Whisper");

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SqlServerOptionsExtension>().Single();

            Assert.Equal("Database=Whisper", extension.ConnectionString);
            Assert.Null(extension.Connection);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:11,代码来源:SqlServerDbContextOptionsExtensionsTest.cs

示例5: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     if (_useInMemory)
     {
         options.UseInMemoryStore();
     }
     else
     {
         options.UseSqlServer(ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString);
     }
 }
开发者ID:rowanmiller,项目名称:Demo-dotnetConf2014,代码行数:11,代码来源:CycleSalesContext.cs

示例6: Can_add_extension_with_connection_using_generic_options

        public void Can_add_extension_with_connection_using_generic_options()
        {
            var options = new DbContextOptions<DbContext>();
            var connection = new SqlConnection();

            options = options.UseSqlServer(connection);

            var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SqlServerOptionsExtension>().Single();

            Assert.Same(connection, extension.Connection);
            Assert.Null(extension.ConnectionString);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:12,代码来源:SqlServerDbContextOptionsExtensionsTest.cs

示例7: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(SqlServerTestDatabase.CreateConnectionString(_databaseName));
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:4,代码来源:SequenceEndToEndTest.cs

示例8: OnConfiguring

 protected override void OnConfiguring(DbContextOptions builder)
 {
     builder.UseSqlServer(@"Server=(localdb)\ProjectsV12;Database=HomeController;Trusted_Connection=True;");
 }
开发者ID:wertzui,项目名称:HomeController,代码行数:4,代码来源:FixtureContext.cs

示例9: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     var connection = ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString;
     options.UseSqlServer(connection);
 }
开发者ID:rowanmiller,项目名称:Demo-dotnetConf2014,代码行数:5,代码来源:CycleSalesContext.cs

示例10: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(SqlServerTestDatabase.NorthwindConnectionString);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:4,代码来源:SqlServerConfigPatternsTest.cs

示例11: OnConfiguring

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

示例12: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(_connection);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:4,代码来源:ExistingConnectionTest.cs

示例13: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(Startup.Configuration.Get("Data:DefaultConnection:ConnectionString"));
 }
开发者ID:freemsly,项目名称:JumpStart-MVC6WebApi,代码行数:4,代码来源:RegistrationDbContext.cs

示例14: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(_nameOrConnectionString);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:4,代码来源:ConnectionStringTest.cs

示例15: OnConfiguring

 protected override void OnConfiguring(DbContextOptions options)
 {
     options.UseSqlServer(_testDatabase.Connection.ConnectionString);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:4,代码来源:SqlServerDatabaseCreationTest.cs


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