• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DbContextOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DbContextOptions的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptions类的具体用法?C# DbContextOptions怎么用?C# DbContextOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DbContextOptions类属于命名空间,在下文中一共展示了DbContextOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: It_disallows_empty_connection_strings

        public void It_disallows_empty_connection_strings()
        {
            var options = new DbContextOptions();

            Assert.Equal(
                Strings.FormatArgumentIsEmpty("connectionString"),
                Assert.Throws<ArgumentException>(() => AtsDbContextExtensions.UseAzureTableStorage(options, "")).Message
                );
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:9,代码来源:AtsDbContextExtensionsTests.cs


示例17: Can_update_an_existing_extension

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


示例18: It_disallows_empty_account_creds

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


示例19: UseInMemoryStore_throws_if_options_are_locked

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


示例20: Is_configured_when_configuration_contains_associated_extension

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DbContextOptionsBuilder类代码示例发布时间:2022-05-24
下一篇:
C# DbContextCustomerRepository类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap