本文整理汇总了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);
}
示例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>();
}
示例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();
}
示例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);
}
}
}
示例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));
}
示例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);
}
示例7: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
var connectionString = @"Server=(LocalDb)\MSSQLLocalDb;Database=AspNetBlog";
optionsBuilder.UseSqlServer(connectionString);
}
示例8: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
//optionsBuilder.Options.
}
示例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);
}
示例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");
}
示例11: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
SqliteConnectionStringBuilder sb = new SqliteConnectionStringBuilder();
sb.DataSource = filename;
optionsBuilder.UseSqlite(sb.ToString());
}
示例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);
}
示例13: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
#if DEBUG
ConnectionString = "Server=(localdb)\\MSSQLLocalDB;Database=Health;Trusted_Connection=True;";
#endif
optionsBuilder.UseSqlServer(ConnectionString);
}
示例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);
}
示例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();
}