コード例 #1
0
        public static void EnsureAdd(IApplicationBuilder app)
        {
            SportDbContext context = app.ApplicationServices.GetRequiredService <SportDbContext>();

            context.Database.Migrate();

            if (!context.Products.Any())
            {
                context.Products.AddRange(
                    new Product
                {
                    Name        = "Kayak",
                    Description = "A boat for one persion",
                    Category    = "Watersports",
                    Price       = 440
                },
                    new Product
                {
                    Name        = "Lifejacket",
                    Description = "Protective and Fashioable",
                    Category    = "Watersports",
                    Price       = 12.5M
                },
                    new Product
                {
                    Name        = "Socer Ball",
                    Description = "Fifa-approved size and weight",
                    Category    = "Ball",
                    Price       = 20.75M
                }

                    );

                context.SaveChanges();
            }
        }
コード例 #2
0
 public ServiceRepository(SportDbContext db)
 {
     context = db;
 }
コード例 #3
0
 public EFProductRepository(SportDbContext db)
 {
     context = db;
 }
コード例 #4
0
 public EFOrderRepository(SportDbContext db)
 {
     _db = db;
 }