protected override void OnConfiguring(DbContextOptions builder) { var dir = Windows.Storage.ApplicationData.Current.LocalFolder.Path; var connection = "Filename=" + System.IO.Path.Combine(dir, "FavoriteForum.db"); builder.UseSQLite(connection); }
public ContactsDbContext(DbContextOptions<ContactsDbContext> options) : base(options) { if (_created) return; Database.Migrate(); _created = true; }
public void SimpleConversion() { var options = new DbContextOptions() .UseInMemoryStore(); using (var db = new CycleSalesContext(options)) { // Arange db.Bikes.Add(new Bike { Bike_Id = 1, Retail = 100M }); db.Bikes.Add(new Bike { Bike_Id = 2, Retail = 99.95M }); db.SaveChanges(); // Act var convertor = new PriceService(db); var results = convertor.CalculateForeignPrices(exchangeRate: 2).ToArray(); // Assert Assert.AreEqual(2, results.Length); Assert.AreEqual(100M, results[0].USPrice); Assert.AreEqual(199.95M, results[0].ForeignPrice); Assert.AreEqual(99.95M, results[1].USPrice); Assert.AreEqual(199.90M, results[1].ForeignPrice); } }
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"); }
protected override void OnConfiguring(DbContextOptions options) { if (!options.IsAlreadyConfigured()) { options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;"); } }
public DbContext CreateContext(string tableName) { var options = new DbContextOptions() .UseModel(CreateModel(tableName)) .UseAzureTableStorage(TestConfig.Instance.ConnectionString); return new DbContext(options); }
public BlavenDbContext(DbContextOptions<BlavenDbContext> options, Action<ModelBuilder> onModelCreating = null) : base(options) { this.Options = options; this.onModelCreating = onModelCreating; }
public virtual DbContextConfiguration Initialize( [NotNull] IServiceProvider externalProvider, [NotNull] IServiceProvider scopedProvider, [NotNull] DbContextOptions contextOptions, [NotNull] DbContext context, ServiceProviderSource serviceProviderSource) { Check.NotNull(externalProvider, "externalProvider"); Check.NotNull(scopedProvider, "scopedProvider"); Check.NotNull(contextOptions, "contextOptions"); Check.NotNull(context, "context"); Check.IsDefined(serviceProviderSource, "serviceProviderSource"); _externalProvider = externalProvider; _services = new ContextServices(scopedProvider); _serviceProviderSource = serviceProviderSource; _contextOptions = contextOptions; _context = context; _dataStoreServices = new LazyRef<DataStoreServices>(() => _services.DataStoreSelector.SelectDataStore(this)); _modelFromSource = new LazyRef<IModel>(() => _services.ModelSource.GetModel(_context, _dataStoreServices.Value.ModelBuilderFactory)); _dataStore = new LazyRef<DataStore>(() => _dataStoreServices.Value.Store); _connection = new LazyRef<DataStoreConnection>(() => _dataStoreServices.Value.Connection); _loggerFactory = new LazyRef<ILoggerFactory>(() => _externalProvider.TryGetService<ILoggerFactory>() ?? new NullLoggerFactory()); _database = new LazyRef<Database>(() => _dataStoreServices.Value.Database); _stateManager = new LazyRef<StateManager>(() => _services.StateManager); return this; }
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(); }
public MainForm() { InitializeComponent(); var builder = new DbContextOptionsBuilder(); builder.UseSqlServer(ConfigurationManager.ConnectionStrings["RemoteDatabase"].ConnectionString); _remoteDatabaseOptions = builder.Options; }
public void Model_can_be_set_explicitly_in_options() { var model = Mock.Of<IModel>(); var options = new DbContextOptions().UseModel(model); Assert.Same(model, options.Model); }
public void It_disallows_empty_account_creds(string name, string key, string paramName) { var options = new DbContextOptions(); Assert.Equal( Strings.FormatArgumentIsEmpty(paramName), Assert.Throws<ArgumentException>(() => AtsDbContextExtensions.UseAzureTableStorage(options, name, key)).Message ); }
public void Can_update_an_existing_extension() { IDbContextOptionsExtensions options = new DbContextOptions(); options.AddOrUpdateExtension<FakeDbContextOptionsExtension1>(e => e.Something += "One"); options.AddOrUpdateExtension<FakeDbContextOptionsExtension1>(e => e.Something += "Two"); Assert.Equal("OneTwo", options.Extensions.OfType<FakeDbContextOptionsExtension1>().Single().Something); }
public void Is_not_available_when_not_configured() { var options = new DbContextOptions(); var configurationMock = new Mock<DbContextConfiguration>(); configurationMock.Setup(m => m.ContextOptions).Returns(options); Assert.False(new SqlServerDataStoreSource(configurationMock.Object).IsAvailable); }
public void Is_not_configured_when_configuration_does_not_contain_associated_extension() { var options = new DbContextOptions(); var configurationMock = new Mock<DbContextConfiguration>(); configurationMock.Setup(m => m.ContextOptions).Returns(options); Assert.False(new SqlServerDataStoreSource(configurationMock.Object).IsConfigured); }
public void UseInMemoryStore_throws_if_options_are_locked() { var options = new DbContextOptions<DbContext>(); options.Lock(); Assert.Equal( GetString("FormatEntityConfigurationLocked", "UseInMemoryStore"), Assert.Throws<InvalidOperationException>(() => options.UseInMemoryStore()).Message); }
public void It_disallows_empty_connection_strings() { var options = new DbContextOptions(); Assert.Equal( Strings.FormatArgumentIsEmpty("connectionString"), Assert.Throws<ArgumentException>(() => AtsDbContextExtensions.UseAzureTableStorage(options, "")).Message ); }
public void UseSQLite_throws_if_options_are_locked() { var options = new DbContextOptions<DbContext>(); options.Lock(); Assert.Equal( GetString("FormatEntityConfigurationLocked", "UseSQLite"), Assert.Throws<InvalidOperationException>(() => options.UseSQLite("Database=DoubleDecker")).Message); }
public void Can_add_extension_with_connection_string() { var options = new DbContextOptions(); options = options.UseSQLite("Database=Crunchie"); var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SQLiteOptionsExtension>().Single(); Assert.Equal("Database=Crunchie", extension.ConnectionString); }
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;"); } }
public void It_sets_batching_options() { var options = new DbContextOptions(); AtsDbContextExtensions.UseAzureTableStorage(options, "not empty", true); var result = GetAtsExtension(options); Assert.NotNull(result); Assert.True(result.UseBatching); }
public void Can_add_extension_with_connection_string_using_generic_options() { var options = new DbContextOptions<DbContext>(); options = options.UseSQLite("Database=Whisper"); var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<SQLiteOptionsExtension>().Single(); Assert.Equal("Database=Whisper", extension.ConnectionString); }
public void Can_add_extension_with_connection_string_using_generic_options() { var options = new DbContextOptions<DbContext>(); options = options.UseInMemoryStore(persist: false); var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<InMemoryOptionsExtension>().Single(); Assert.False(extension.Persist); }
public void Is_available_when_configured() { var options = new DbContextOptions(); ((IDbContextOptionsExtensions)options).AddOrUpdateExtension<SqlServerOptionsExtension>(e => { }); var configurationMock = new Mock<DbContextConfiguration>(); configurationMock.Setup(m => m.ContextOptions).Returns(options); Assert.True(new SqlServerDataStoreSource(configurationMock.Object).IsAvailable); }
public void Is_configured_when_configuration_contains_associated_extension() { IDbContextOptionsExtensions options = new DbContextOptions(); options.AddOrUpdateExtension<InMemoryOptionsExtension>(e => { }); var configurationMock = new Mock<DbContextConfiguration>(); configurationMock.Setup(m => m.ContextOptions).Returns(options); Assert.True(new InMemoryDataStoreSource(configurationMock.Object).IsConfigured); }
public MigrationsSqliteFixture() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlite() .BuildServiceProvider(); _options = new DbContextOptionsBuilder() .UseInternalServiceProvider(serviceProvider) .UseSqlite("Data Source=" + nameof(MigrationsSqliteTest) + ".db").Options; }
public void It_constructs_connection_string() { var options = new DbContextOptions(); AtsDbContextExtensions.UseAzureTableStorage(options, "Moria", "mellon"); var result = GetAtsExtension(options); Assert.NotNull(result); Assert.Equal("DefaultEndpointsProtocol=https;AccountName=Moria;AccountKey=mellon;", result.ConnectionString); }
public void Can_add_extension_using_persist_true() { var options = new DbContextOptions(); options = options.UseInMemoryStore(persist: true); var extension = ((IDbContextOptionsExtensions)options).Extensions.OfType<InMemoryOptionsExtension>().Single(); Assert.True(extension.Persist); }
protected override void OnConfiguring(DbContextOptions options) { if (_useInMemory) { options.UseInMemoryStore(); } else { options.UseSqlServer(ConfigurationManager.ConnectionStrings["CycleSalesConnection"].ConnectionString); } }
public AppIdentityDbContext(DbContextOptions <AppIdentityDbContext> options) : base(options) { }
public Fit4LifeDbContext(DbContextOptions <Fit4LifeDbContext> options) : base(options) { }
public Context(DbContextOptions <Context> options) : base(options) { }
public HsDbFirstRealAspNetProjectContext(DbContextOptions <HsDbFirstRealAspNetProjectContext> options) : base(options) { }
public scoreContext(DbContextOptions <scoreContext> options) : base(options) { }
public WarriorContext(DbContextOptions <WarriorContext> options) : base(options) { }
public ApplicationDbContext(DbContextOptions <ApplicationDbContext> options) : base(options) { }
public ShopContext(DbContextOptions <ShopContext> options) : base(options) { }
public DataContext(DbContextOptions <DataContext> options) : base(options) { }
public TravelBlogContext(DbContextOptions <TravelBlogContext> options) : base(options) { }
public AccountContext(DbContextOptions <AccountContext> options) : base(options) { }
public StudentDBContext(DbContextOptions options) : base(options) { }
public QuickBuyContexto(DbContextOptions options) : base(options) { }
public BriefContext(DbContextOptions <BriefContext> options) : base(options) { }
public TodoContext(DbContextOptions <TodoContext> dbOptions) : base(dbOptions) { }
public VegaDbContext(DbContextOptions <VegaDbContext> options) : base(options) { //System.configuration.ConfigurationManager }
public CityInfoContext(DbContextOptions <CityInfoContext> options) : base(options) { Database.Migrate(); Database.Migrate(); }
static CustomerTestController() { dbContextOptions = new DbContextOptionsBuilder<Book_Store_DbContext>().UseSqlServer(connectionString).Options; }
public DbFirstDemoContext(DbContextOptions <DbFirstDemoContext> options) : base(options) { }
public restaurantMP31Context(DbContextOptions <restaurantMP31Context> options) : base(options) { }
public HackermanContext(DbContextOptions <HackermanContext> options) : base(options) { }
public LotteryDbContext(DbContextOptions options) : base(options) { }
public InvoiceGeneratorAuthorizationContext(DbContextOptions <InvoiceGeneratorAuthorizationContext> options) : base(options) { }
public SchoolContext(DbContextOptions <SchoolContext> options) : base(options) { }
/// <inheritdoc /> public DbContextBase(DbContextOptions options) : base(options) { }
public ReviewContext(DbContextOptions <ReviewContext> options) : base(options) { }
public EmpDBContext(DbContextOptions<EmpDBContext> options) : base(options) { }
public CartContext(DbContextOptions <CartContext> options) : base(options) { Database.EnsureCreated(); }
public SimpleDbContext(DbContextOptions <SimpleDbContext> options) : base(options) { }
public MyshopContext(DbContextOptions<MyshopContext> options) : base(options) { }
private static void SeedDatabase(DbContextOptions options) { using (var db = new GreetingDbContext(options)) { db.Greetings.Add(new Greeting{Name = "First Greeting", TimestampUtc = DateTime.Now.ToUniversalTime()}); db.Greetings.Add(new Greeting{Name = "Second Greeting", TimestampUtc = DateTime.Now.ToUniversalTime()}); db.SaveChanges(); } }