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


C# DbContextOptionsBuilder.UseInMemoryDatabase方法代码示例

本文整理汇总了C#中DbContextOptionsBuilder.UseInMemoryDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptionsBuilder.UseInMemoryDatabase方法的具体用法?C# DbContextOptionsBuilder.UseInMemoryDatabase怎么用?C# DbContextOptionsBuilder.UseInMemoryDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbContextOptionsBuilder的用法示例。


在下文中一共展示了DbContextOptionsBuilder.UseInMemoryDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ContextRegistry

        public ContextRegistry()
        {
            optionsBuilder = new DbContextOptionsBuilder<ProductContext>();
            optionsBuilder.UseInMemoryDatabase();

            For<IContext>().Use("Create new instance of data context", x => new ProductContext(optionsBuilder.Options));
        }
开发者ID:Cheers,项目名称:Samples,代码行数:7,代码来源:ContextRegistry.cs

示例2: PreInitialize

        public override void PreInitialize()
        {
            Configuration.UnitOfWork.IsTransactional = false; //EF Core InMemory DB does not support transactions

            var services = new ServiceCollection()
                .AddEntityFrameworkInMemoryDatabase();

            var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(
                IocManager.IocContainer,
                services
            );

            var builder = new DbContextOptionsBuilder<BloggingDbContext>();
            builder.UseInMemoryDatabase()
                .UseInternalServiceProvider(serviceProvider);

            IocManager.IocContainer.Register(
                Component
                    .For<DbContextOptions<BloggingDbContext>>()
                    .Instance(builder.Options)
                    .LifestyleSingleton()
            );

            Configuration.ReplaceService<IRepository<Post, Guid>>(() =>
            {
                IocManager.IocContainer.Register(
                    Component.For<IRepository<Post, Guid>, IPostRepository, PostRepository>()
                        .ImplementedBy<PostRepository>()
                        .LifestyleTransient()
                );
            });
        }
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:32,代码来源:EntityFrameworkCoreTestModule.cs

示例3: HomeControllerTests

        public HomeControllerTests()
        {
            // Database setup
            var services = new ServiceCollection();
            services.AddEntityFramework()
                    .AddSqlServer()
                    .AddInMemoryDatabase()
                    .AddDbContext<DataDbContext>(options =>
                        options.UseInMemoryDatabase()
                    );

            // Dependencies initializations
            _pageConfiguration = new FakePageConfiguration();

            var optionsBuilder = new DbContextOptionsBuilder<DataDbContext>();
            optionsBuilder.UseInMemoryDatabase();
            _dataDbContext = new DataDbContext(optionsBuilder.Options);

            _contentRepository = new ContentRepository(_dataDbContext);
            _humanReadableContentService = new HumanReadableContentService(_pageConfiguration, _contentRepository);

            _languageManipulationService = new LanguageManipulationService();

            // Controller initialization
            _homeController = new PersonalWebsite.Controllers.HomeController(
                _pageConfiguration,
                _humanReadableContentService,
                _languageManipulationService
            );
        }
开发者ID:nettsundere,项目名称:PersonalWebsite,代码行数:30,代码来源:HomeControllerTests.cs

示例4: CreateStore

        private static IInMemoryDatabase CreateStore(IServiceProvider serviceProvider, bool persist)
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            return InMemoryTestHelpers.Instance.CreateContextServices(serviceProvider, optionsBuilder.Options).GetRequiredService<IInMemoryDatabase>();
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:7,代码来源:InMemoryDatabaseCreatorTest.cs

示例5: CreateOptions

        protected override DbContextOptions CreateOptions(string databaseName)
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            return optionsBuilder.Options;
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:7,代码来源:MonsterFixupInMemoryTest.cs

示例6: GetPendingOrders

        public void GetPendingOrders()
        {
            var builder = new DbContextOptionsBuilder<UnicornStoreContext>();
            builder.UseInMemoryDatabase(persist: true);
            var options = builder.Options;

            using (var context = new UnicornStoreContext(options))
            {
                var orders = new List<Order>
                {
                    new Order { State = OrderState.CheckingOut, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.Placed, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.Filling, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.ReadyToShip, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.Shipped, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.Delivered, ShippingDetails = new OrderShippingDetails() },
                    new Order { State = OrderState.Cancelled, ShippingDetails = new OrderShippingDetails() },
                };

                context.AddRange(orders);
                context.AddRange(orders.Select(o => o.ShippingDetails));
                context.SaveChanges();
            }

            using (var context = new UnicornStoreContext(options))
            {
                var controller = new ShippingController(context);
                var orders = controller.PendingOrders();
                Assert.Equal(1, orders.Count());
            }
        }
开发者ID:jwendl,项目名称:UnicornStore,代码行数:31,代码来源:ShippingControllerTests.cs

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

示例8: Seed

        public Seed()
        {
            _context = new DbContextOptionsBuilder<Context>();
            _context.UseInMemoryDatabase();

            BrandSeed();
            CarSeed();
        }
开发者ID:nicolastakashi,项目名称:angular2-car-app,代码行数:8,代码来源:Seed.cs

示例9: Can_add_extension_using_persist_true

        public void Can_add_extension_using_persist_true()
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase(persist: true);

            var extension = (InMemoryOptionsExtension)optionsBuilder.Options.Extensions.Single();

            Assert.True(extension.Persist);
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:9,代码来源:InMemoryDbContextOptionsExtensionsTest.cs

示例10: Can_add_extension_with_connection_string_using_generic_builder

        public void Can_add_extension_with_connection_string_using_generic_builder()
        {
            var optionsBuilder = new DbContextOptionsBuilder<DbContext>();
            optionsBuilder.UseInMemoryDatabase(persist: false);

            var extension = (InMemoryOptionsExtension)optionsBuilder.Options.Extensions.Single();

            Assert.False(extension.Persist);
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:9,代码来源:InMemoryDbContextOptionsExtensionsTest.cs

示例11: GamePlatformRepositoryTests

        public GamePlatformRepositoryTests()
        {
            var db = new DbContextOptionsBuilder<TeammateOnlineContext>();
            db.UseInMemoryDatabase();
            context = new TeammateOnlineContext(db.Options);

            gamePlatformRepository = new GamePlatformRepository(context);

            SeedData();
        }
开发者ID:thors1982,项目名称:TeammateOnlineApi,代码行数:10,代码来源:GamePlatformRepositoryTests.cs

示例12: UserProfileRepositoryTests

        public UserProfileRepositoryTests()
        {
            var db = new DbContextOptionsBuilder<TeammateOnlineContext>();
            db.UseInMemoryDatabase();
            context = new TeammateOnlineContext(db.Options);

            userProfileRepository = new UserProfileRepository(context);

            SeedData();
        }
开发者ID:thors1982,项目名称:TeammateOnlineApi,代码行数:10,代码来源:UserProfileRepositoryTests.cs

示例13: Music_store_project_to_mapped_entity

        public void Music_store_project_to_mapped_entity()
        {
            var serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddInMemoryDatabase()
                    .ServiceCollection()
                    .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();
            optionsBuilder.UseInMemoryDatabase();

            using (var db = new MusicStoreContext(serviceProvider, optionsBuilder.Options))
            {
                var albums = GetAlbums("~/Images/placeholder.png", Genres, Artists);

                db.Genres.AddRange(Genres.Values);
                db.Artists.AddRange(Artists.Values);
                db.Albums.AddRange(albums);

                db.SaveChanges();
            }

            using (var db = new MusicStoreContext(serviceProvider, optionsBuilder.Options))
            {
                var q = from album in db.Albums
                    join genre in db.Genres on album.GenreId equals genre.GenreId
                    join artist in db.Artists on album.ArtistId equals artist.ArtistId
                    select new Album
                        {
                            ArtistId = album.ArtistId,
                            AlbumArtUrl = album.AlbumArtUrl,
                            AlbumId = album.AlbumId,
                            GenreId = album.GenreId,
                            Price = album.Price,
                            Title = album.Title,
                            Artist = new Artist
                                {
                                    ArtistId = album.ArtistId,
                                    Name = artist.Name
                                },
                            Genre = new Genre
                                {
                                    GenreId = album.GenreId,
                                    Name = genre.Name
                                }
                        };

                var albums = q.ToList();

                Assert.Equal(462, albums.Count);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:53,代码来源:MusicStoreQueryTests.cs

示例14: TestDatabaseStore

        /// <summary>
        /// Constructor.
        /// </summary>
        public TestDatabaseStore()
        {
            var serviceProvider = new ServiceCollection()
                .AddEntityFrameworkInMemoryDatabase()
                .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
            optionsBuilder.UseInMemoryDatabase()
                .UseInternalServiceProvider(serviceProvider);

            Options = optionsBuilder.Options;
        }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:15,代码来源:TestDatabaseStore.cs

示例15: Startup

        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables();
            Configuration = builder.Build();

            _context = new DbContextOptionsBuilder<Context>();
            _context.UseInMemoryDatabase();

        }
开发者ID:nicolastakashi,项目名称:angular2-car-app,代码行数:12,代码来源:Startup.cs


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