本文整理汇总了C#中DbContextOptions类的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptions类的具体用法?C# DbContextOptions怎么用?C# DbContextOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbContextOptions类属于命名空间,在下文中一共展示了DbContextOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContactsDbContext
public ContactsDbContext(DbContextOptions<ContactsDbContext> options)
: base(options)
{
if (_created) return;
Database.Migrate();
_created = true;
}
示例2: BlavenDbContext
public BlavenDbContext(DbContextOptions<BlavenDbContext> options, Action<ModelBuilder> onModelCreating = null)
: base(options)
{
this.Options = options;
this.onModelCreating = onModelCreating;
}
示例3: 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");
}
示例4: CreateContext
public DbContext CreateContext(string tableName)
{
var options = new DbContextOptions()
.UseModel(CreateModel(tableName))
.UseAzureTableStorage(TestConfig.Instance.ConnectionString);
return new DbContext(options);
}
示例5: Initialize
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;
}
示例6: OnConfiguring
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);
}
示例7: SimpleConversion
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);
}
}
示例8: OnConfiguring
protected override void OnConfiguring(DbContextOptions options)
{
if (!options.IsAlreadyConfigured())
{
options.UseSqlServer(@"Server=(localdb)\v11.0;Database=CycleSales;integrated security=True;");
}
}
示例9: InheritanceSqliteFixture
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();
}
示例10: Model_can_be_set_explicitly_in_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);
}
示例11: MainForm
public MainForm()
{
InitializeComponent();
var builder = new DbContextOptionsBuilder();
builder.UseSqlServer(ConfigurationManager.ConnectionStrings["RemoteDatabase"].ConnectionString);
_remoteDatabaseOptions = builder.Options;
}
示例12: Is_not_available_when_not_configured
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);
}
示例13: SeedDatabase
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();
}
}
示例14: Is_not_configured_when_configuration_does_not_contain_associated_extension
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);
}
示例15: UseSQLite_throws_if_options_are_locked
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);
}