Esempio n. 1
0
        /// <summary>
        /// Enable HierarchyId mappings.
        /// </summary>
        /// <param name="optionsBuilder">The builder being used to configure in-memory database.</param>
        /// <returns>The options builder so that further configuration can be chained.</returns>
        public static InMemoryDbContextOptionsBuilder UseHierarchyId(
            this InMemoryDbContextOptionsBuilder optionsBuilder)
        {
            var coreOptionsBuilder = ((IInMemoryDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;

            var extension = coreOptionsBuilder.Options.FindExtension <InMemoryHierarchyIdOptionsExtension>()
                            ?? new InMemoryHierarchyIdOptionsExtension();

            ((IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder).AddOrUpdateExtension(extension);

            return(optionsBuilder);
        }
        /// <summary>
        /// Enable HierarchyId mappings.
        /// </summary>
        /// <param name="optionsBuilder">The builder being used to configure in-memory database.</param>
        /// <returns>The options builder so that further configuration can be chained.</returns>
        public static InMemoryDbContextOptionsBuilder UseHierarchyId(
            this InMemoryDbContextOptionsBuilder optionsBuilder)
        {
            // Work around dotnet/efcore#23669
            var optionsBuilderPropertyInfo = optionsBuilder.GetType().GetProperty("OptionsBuilder", BindingFlags.Instance | BindingFlags.NonPublic);
            var coreOptionsBuilder         = optionsBuilderPropertyInfo.GetValue(optionsBuilder) as DbContextOptionsBuilder;

            var extension = coreOptionsBuilder.Options.FindExtension <InMemoryHierarchyIdOptionsExtension>()
                            ?? new InMemoryHierarchyIdOptionsExtension();

            ((IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder).AddOrUpdateExtension(extension);

            return(optionsBuilder);
        }
        public async Task Test_CreateDbContextAndBuildModel(int start, int end, string name)
        {
            var options = InMemoryDbContextOptionsBuilder.GetDefault();
            var data    = TestDataBuilder.CreateDefault();

            using var context = new MaplineDbContext(options)
                  {
                      DataBuilder = data
                  };

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Languages.Add(new Language
            {
                YearStart = start,
                YearEnd   = end,
                Name      = name
            });

            var saveChangesResult = await context.SaveChangesAsync();

            Assert.Equal(expected: 1, actual: saveChangesResult);
        }
 private void OnConfiguringInMemory(InMemoryDbContextOptionsBuilder optionsBuilder) => OnConfiguringInMemory(ApplicationConfiguration, optionsBuilder);
 /// <summary>
 /// Configures the in-memory database to be used for this context.
 /// </summary>
 /// <param name="applicationConfiguration">
 /// Configuration information for the application.
 /// </param>
 /// <param name="optionsBuilder">
 /// A builder that is used to create or modify options for this context.
 /// </param>
 protected virtual void OnConfiguringInMemory(IConfiguration applicationConfiguration, InMemoryDbContextOptionsBuilder optionsBuilder)
 {
     return;
 }
Esempio n. 6
0
 /// <summary>
 /// Configures the in-memory database to be used for this context.
 /// </summary>
 /// <param name="applicationConfiguration">
 /// Configuration information for the application.
 /// </param>
 /// <param name="optionsBuilder">
 /// A builder that is used to create or modify options for this context.
 /// </param>
 protected sealed override void OnConfiguringInMemory(IConfiguration applicationConfiguration, InMemoryDbContextOptionsBuilder optionsBuilder) => base.OnConfiguringInMemory(applicationConfiguration, optionsBuilder);
Esempio n. 7
0
 /// <summary>
 /// Configures the in-memory database to be used for this context.
 /// </summary>
 /// <param name="applicationConfiguration">
 /// Configuration information for the application.
 /// </param>
 /// <param name="optionsBuilder">
 /// A builder that is used to create or modify options for this context.
 /// </param>
 protected sealed override void OnConfiguringInMemory(IConfiguration applicationConfiguration, InMemoryDbContextOptionsBuilder optionsBuilder) => throw new InvalidOperationException();