Esempio n. 1
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            NetCoreProjectDbContext context = app.ApplicationServices
                                              .CreateScope().ServiceProvider.GetRequiredService <NetCoreProjectDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Products.Any())
            {
                context.Products.AddRange(
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Lifejacket",
                    Description = "protective and fashionable",
                    Category    = "C",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                },
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one person",
                    Category    = "Watersports",
                    Price       = 275
                }
                    );
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 public EFStoreRespository(NetCoreProjectDbContext ctx)
 {
     context = ctx;
 }