Exemple #1
0
        static void ContextAddInfo()
        {
            using var context = new ContosoPetsContext();

            var squeakyBone = new Product()
            {
                Name  = "Squeaky Bone Dog",
                Price = 4.99M
            };

            var tennisBall = new Product()
            {
                Name  = "Tennis ball 3-Pack",
                Price = 9.99M
            };

            context.Add(squeakyBone);
            context.Add(tennisBall);

            context.SaveChanges();
        }
Exemple #2
0
        private static void SetupDemoProducts()
        {
            using ContosoPetsContext context = new ContosoPetsContext();

            Product squeakyBone = new Product()
            {
                Name  = "Squeaky Dog Bone",
                Price = 4.99m
            };

            context.Products.Add(squeakyBone);

            Product tennisBalls = new Product()
            {
                Name  = "Tennis Ball 3-Pack",
                Price = 9.99m
            };

            context.Add(tennisBalls);

            context.SaveChanges();
        }
Exemple #3
0
        private static void SeedDb(ContosoPetsContext context)
        {
            context.Database.ExecuteSqlRaw("DELETE FROM dbo.Products");
            context.Database.ExecuteSqlRaw("DBCC CHECKIDENT('dbo.Products', RESEED, 0)");

            Product squeakyBone = new Product
            {
                Name  = "Squeaky Dog Bone",
                Price = 4.99M
            };

            context.Products.Add(squeakyBone);

            Product tennisBalls = new Product
            {
                Name  = "Tennis Ball 3-Pack",
                Price = 9.99M
            };

            context.Add(tennisBalls);

            context.SaveChanges();
        }