Exemplo n.º 1
0
        protected override void Seed(InheritanceContext context)
        {
            base.Seed(context);

            ChangesDate = new DateTime(2010, 1, 1);

            context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Animal).Select(e => e.Entity));
            context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Plant).Select(e => e.Entity));
            context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Country).Select(e => e.Entity));
            context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Drink).Select(e => e.Entity));
            context.SaveChanges();

            var tableNames = new List <string>
            {
                "Animals",
                "Plants",
                "Countries",
                "Drinks"
            };

            foreach (var tableName in tableNames)
            {
                context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] SET (SYSTEM_VERSIONING = OFF)");
                context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] DROP PERIOD FOR SYSTEM_TIME");

                context.Database.ExecuteSqlRaw($"UPDATE [{tableName + "History"}] SET PeriodStart = '2000-01-01T01:00:00.0000000Z'");
                context.Database.ExecuteSqlRaw($"UPDATE [{tableName + "History"}] SET PeriodEnd = '2020-07-01T07:00:00.0000000Z'");

                context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] ADD PERIOD FOR SYSTEM_TIME ([PeriodStart], [PeriodEnd])");
                context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[{tableName + "History"}]))");
            }
        }
Exemplo n.º 2
0
            protected override void OnItemAdded(AnimationBase animation)
            {
                base.OnItemAdded(animation);

                InheritanceContext?.Attach(animation);

                _compositeAnimation.OnAnimationAdded(animation);
            }
Exemplo n.º 3
0
 public override InMemoryTestStore CreateTestStore()
 => InMemoryTestStore.GetOrCreateShared(
     DatabaseName,
     () =>
 {
     using (var context = new InheritanceContext(_options))
     {
         InheritanceModelInitializer.SeedData(context);
     }
 });
Exemplo n.º 4
0
            protected override void OnItemRemoved(AnimationBase animation)
            {
                InheritanceContext?.Detach(animation);

                animation.RelativeTime = 0.0;

                _compositeAnimation.OnAnimationRemoved(animation);

                base.OnItemRemoved(animation);
            }
Exemplo n.º 5
0
        public override InheritanceContext CreateContext(OracleTestStore testStore)
        {
            var context = new InheritanceContext(
                new DbContextOptionsBuilder(_options)
                .UseOracle(testStore.Connection, b => b.ApplyConfiguration())
                .Options);

            context.Database.UseTransaction(testStore.Transaction);

            return(context);
        }
        protected void SeedData(InheritanceContext context)
        {
            var kiwi = new Kiwi
            {
                Species      = "Apteryx haastii",
                Name         = "Great spotted kiwi",
                IsFlightless = true,
                FoundOn      = Island.South
            };

            var eagle = new Eagle
            {
                Species = "Aquila chrysaetos canadensis",
                Name    = "American golden eagle",
                Group   = EagleGroup.Booted
            };

            eagle.Prey.Add(kiwi);

            var rose = new Rose
            {
                Species   = "Rosa canina",
                Name      = "Dog-rose",
                HasThorns = true
            };

            var daisy = new Daisy
            {
                Species = "Bellis perennis",
                Name    = "Common daisy"
            };

            var nz = new Country {
                Id = 1, Name = "New Zealand"
            };

            nz.Animals.Add(kiwi);

            var usa = new Country {
                Id = 2, Name = "USA"
            };

            usa.Animals.Add(eagle);

            context.Set <Animal>().Add(kiwi);
            context.Set <Bird>().Add(eagle);
            context.Set <Country>().Add(nz);
            context.Set <Country>().Add(usa);
            context.Set <Rose>().Add(rose);
            context.Set <Daisy>().Add(daisy);

            context.SaveChanges();
        }
Exemplo n.º 7
0
        public override InheritanceContext CreateContext(SqliteTestStore testStore)
        {
            var context = new InheritanceContext(
                new DbContextOptionsBuilder()
                .UseSqlite(
                    testStore.Connection,
                    b => b.SuppressForeignKeyEnforcement())
                .UseInternalServiceProvider(_serviceProvider).Options);

            context.Database.UseTransaction(testStore.Transaction);

            return(context);
        }
Exemplo n.º 8
0
    public static void Seed(InheritanceContext context)
    {
        var animals   = InheritanceData.CreateAnimals();
        var countries = InheritanceData.CreateCountries();
        var drinks    = InheritanceData.CreateDrinks();
        var plants    = InheritanceData.CreatePlants();

        InheritanceData.WireUp(animals, countries);

        context.Animals.AddRange(animals);
        context.Countries.AddRange(countries);
        context.Drinks.AddRange(drinks);
        context.Plants.AddRange(plants);

        context.SaveChanges();
    }
        private void GetEntityWithAuditHistoryQuery <T>(InheritanceContext context, IQueryable <T> query)
            where T : Animal
        {
            var queryTypeQuery = context.Set <AnimalQuery>().FromSqlRaw(NormalizeDelimitersInRawString("Select * from [Animals]"));

            var animalQuery = query.Cast <Animal>();

            var joinQuery =
                from animal in animalQuery
                join keylessanimal in queryTypeQuery on animal.Name equals keylessanimal.Name
                select new { animal, keylessanimal };

            var result = joinQuery.ToList();

            Assert.Single(result);
        }
Exemplo n.º 10
0
 public override SqliteTestStore CreateTestStore()
 {
     return(SqliteTestStore.GetOrCreateShared(
                DatabaseName, () =>
     {
         using (var context = new InheritanceContext(
                    new DbContextOptionsBuilder()
                    .UseSqlite(SqliteTestStore.CreateConnectionString(DatabaseName))
                    .UseInternalServiceProvider(_serviceProvider)
                    .Options))
         {
             context.Database.EnsureClean();
             InheritanceModelInitializer.SeedData(context);
         }
     }));
 }
Exemplo n.º 11
0
 public override OracleTestStore CreateTestStore()
 {
     return(OracleTestStore.GetOrCreateShared(
                DatabaseName, () =>
     {
         using (var context = new InheritanceContext(
                    new DbContextOptionsBuilder(_options)
                    .UseOracle(
                        OracleTestStore.CreateConnectionString(DatabaseName),
                        b => b.ApplyConfiguration())
                    .Options))
         {
             context.Database.EnsureCreated();
             InheritanceModelInitializer.SeedData(context);
         }
     }));
 }
Exemplo n.º 12
0
 static void Main(string[] args)
 {
     using (var context = new InheritanceContext("TPH"))
     {
         context.ModelCreating += OnModelCreating;
         context.Database.Initialize(true);
         context.Database.Log = Console.WriteLine;
         IQueryable <Payment> payments = from p in context.Payments select p;
         foreach (var payment in payments)
         {
             Console.WriteLine(payment.ToString());
         }
         IQueryable <CreditCardPayment> creditCards =
             from p in context.Payments.OfType <CreditCardPayment>() select p;
         foreach (var creditCard in creditCards)
         {
             Console.WriteLine(creditCard.ToString());
         }
         Console.ReadLine();
     }
 }