コード例 #1
0
        private static void AddOneSuperHero()
        {
            var SuperHero = new SuperHero()
            {
                Name = "FoxBear"
            };

            using (var context = new SuperHeroContext())
            {
                context.SuperHeroes.Add(SuperHero);
                context.SaveChanges();
            }
        }
コード例 #2
0
        public void AddHero(SuperHeroViewModel vm)
        {
            byte[] picture = new byte[vm.ImageToUpload.Length];
            using (var stream = vm.ImageToUpload.OpenReadStream())
            {
                stream.Read(picture, 0, (int)vm.ImageToUpload.Length);
            }
            SuperHeroModel model = new SuperHeroModel()
            {
                Name        = vm.Name,
                ContentType = vm.ImageToUpload.ContentType,
                Health      = 100,
                Power       = vm.Power,
                Side        = vm.Side,
                Speed       = vm.Speed,
                Magic       = vm.Magic,
                Image       = picture
            };

            dbcontext.SuperHeroes.Add(model);
            dbcontext.SaveChanges();
        }
コード例 #3
0
 private static void AddSomeSuperHeros()
 {
     SuperHero[] superHeroes =
     {
         new SuperHero()
         {
             Name = "Superman"
         },
         new SuperHero()
         {
             Name = "Batman"
         },
         new SuperHero()
         {
             Name = "Wonderwoman"
         }
     };
     using (var context = new SuperHeroContext())
     {
         context.SuperHeroes.AddRange(superHeroes);
         context.SaveChanges();
     }
 }