Пример #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ProductInventoryContext(
                       serviceProvider.GetRequiredService <DbContextOptions <ProductInventoryContext> >()))
            {
                var user1 = new User("Joriz");

                if (!context.Users.Any())
                {
                    context.Users.AddRange(
                        user1
                        );
                }

                if (!context.Products.Any())
                {
                    context.Products.AddRange(
                        new Product("Milo", "Chocolate drink", 1, "some link here"),
                        new Product("Bear brand", "Milk drink", 1, "some link here"),
                        new Product("Slippers", "rubber", 2, "some link here"),
                        new Product("T-shirt", "clothes", 2, "some link here")
                        );
                }

                if (!context.Categories.Any())
                {
                    context.Categories.AddRange(
                        new Category("Food"),
                        new Category("Clothes")
                        );
                }

                context.SaveChanges();
            }
        }
 public ProductInventoryRepository(ProductInventoryContext context) : base(context)
 {
 }
Пример #3
0
 public ProductInventoryRepository(ProductInventoryContext productInventoryContext)
 {
     ProductInventoryContext = productInventoryContext;
     DbSet = ProductInventoryContext.Set <TEntity>();
 }
Пример #4
0
 public UserRepository(ProductInventoryContext productInventoryContext) : base(productInventoryContext)
 {
 }
 public CategoryRepository(ProductInventoryContext productInventoryContext) : base(productInventoryContext)
 {
 }
 public Repository(ProductInventoryContext context)
 {
     _context = context;
 }