本文整理汇总了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);
}
示例2: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
if (!options.IsAlreadyConfigured())
{
options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
}
}
示例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;");
}
}
示例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);
}
示例5: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
if (_useInMemory)
{
options.UseInMemoryStore();
}
else
{
options.UseSqlServer(ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString);
}
}
示例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);
}
示例7: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(SqlServerTestDatabase.CreateConnectionString(_databaseName));
}
示例8: OnConfiguring
protected override void OnConfiguring(DbContextOptions builder)
{
builder.UseSqlServer(@"Server=(localdb)\ProjectsV12;Database=HomeController;Trusted_Connection=True;");
}
示例9: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
var connection = ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString;
options.UseSqlServer(connection);
}
示例10: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(SqlServerTestDatabase.NorthwindConnectionString);
}
示例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);
}
示例12: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(_connection);
}
示例13: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(Startup.Configuration.Get("Data:DefaultConnection:ConnectionString"));
}
示例14: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(_nameOrConnectionString);
}
示例15: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(_testDatabase.Connection.ConnectionString);
}