示例#1
0
        private static void AddRandomData()
        {
            var RNG = new Random();

            // For each battle, what is the chance that the hero was apart of it.
            const int heroChanceToBeInABattle = 80;             // Out of 100


            List <SuperHero> heroes = HeroCreator.CreateRandom(10, RNG);

            List <Battle> battles = BattleCreator.CreateRandom(10);


            WriteHighlightedLine("Assigning battles to heroes.. Randomly!");
            heroes.ForEach(hero =>
            {
                battles.ForEach(battle =>
                {
                    if (RNG.Next(1, 101) < 80)
                    {
                        hero.SuperHeroBattles.Add(SuperHeroBattle.CreateInstance(hero, battle));
                    }
                });
            });
            WriteHighlightedLine("Assignment succeeded");

            using (var context = new SuperHeroDbContext())
            {
                context.SuperHeroes.AddRange(heroes);
                context.Battles.AddRange(battles);

                context.SaveChanges();
            }
        }
示例#2
0
        private static void AddOneSuperHeroWithRelatedData()
        {
            var hero = HeroCreator.CreateAllMightFromBNHA();


            var battle = BattleCreator.CreateRandom();


            var superHeroBattle = SuperHeroBattle.CreateInstance(hero, battle);

            hero.SuperHeroBattles.Add(superHeroBattle);

            battle.SuperHeroBattles.Add(superHeroBattle);

            using (var context = new SuperHeroDbContext())
            {
                context.Battles.Add(battle);
                context.SuperHeroes.Add(hero);
                context.SaveChanges();
            }
        }