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


C# DbContextOptions类代码示例

本文整理汇总了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;
 }
开发者ID:elanderson,项目名称:ASP.NET-Core-SPAs,代码行数:7,代码来源:ContactsDbContext.cs

示例2: BlavenDbContext

        public BlavenDbContext(DbContextOptions<BlavenDbContext> options, Action<ModelBuilder> onModelCreating = null)
            : base(options)
        {
            this.Options = options;

            this.onModelCreating = onModelCreating;
        }
开发者ID:sebnilsson,项目名称:Blaven,代码行数:7,代码来源:BlavenDbContext.cs

示例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");
        }
开发者ID:orome656,项目名称:HOFCServerNet,代码行数:31,代码来源:Program.cs

示例4: CreateContext

 public DbContext CreateContext(string tableName)
 {
     var options = new DbContextOptions()
         .UseModel(CreateModel(tableName))
         .UseAzureTableStorage(TestConfig.Instance.ConnectionString);
     return new DbContext(options);
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:7,代码来源:TestFixture.cs

示例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;
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:28,代码来源:DbContextConfiguration.cs

示例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);
        }
开发者ID:llenroc,项目名称:AwfulMetro,代码行数:7,代码来源:FavoriteForumContext.cs

示例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);
            }
        }
开发者ID:rowanmiller,项目名称:Demo-EF7,代码行数:26,代码来源:PriceConvertorTests.cs

示例8: 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

示例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();
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:59,代码来源:InheritanceSqliteFixture.cs

示例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);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:8,代码来源:DbContextOptionsTest.cs

示例11: MainForm

        public MainForm()
        {
            InitializeComponent();

            var builder = new DbContextOptionsBuilder();
            builder.UseSqlServer(ConfigurationManager.ConnectionStrings["RemoteDatabase"].ConnectionString);
            _remoteDatabaseOptions = builder.Options;
        }
开发者ID:rowanmiller,项目名称:Demo-EFCore,代码行数:8,代码来源:MainForm.cs

示例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);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:9,代码来源:SqlServerDataStoreSourceTest.cs

示例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();
     }
 }
开发者ID:jp7677,项目名称:hellocoreclr,代码行数:9,代码来源:TestserverStartup.cs

示例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);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:9,代码来源:SqlServerDataStoreSourceTest.cs

示例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);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:9,代码来源:SQLiteDbContextOptionsExtensionsTest.cs


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