Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using WebApplication4.Models;
- namespace WebApplication4
- {
- internal static class Program
- {
- private static void Main(string[] args)
- {
- using var context = new ApplicationContext();
- if (!context.Products.Any())
- {
- context.Products.AddRange(
- new Product
- {
- Id = 0,
- Category = "T-shirt",
- Brand = "Emporio Armani",
- Collection = "Summer 2019",
- ProductColor = "purple",
- Amount = 10
- },
- new Product
- {
- Id = 1,
- Category = "Jacket",
- Brand = "Tommy Hilfiger",
- Collection = "Spring 2018",
- ProductColor = "black",
- Amount = 5
- },
- new Product
- {
- Id = 2,
- Category = "Pants",
- Brand = "Hugo Boss",
- Collection = "Hugo Boss pants 2019",
- ProductColor = "black",
- Amount = 5
- },
- new Product
- {
- Id = 3,
- Category = "Shoes",
- Brand = "Nike",
- Collection = "Airforce 1 2017",
- ProductColor = "black",
- Amount = 1
- }
- );
- context.Brands.AddRange(
- new Brand
- {
- BrandId = 3,
- BrandName = "Emporio Armani"
- },
- new Brand
- {
- BrandId = 2,
- BrandName = "Tommy Hilfiger"
- },
- new Brand
- {
- BrandId = 1,
- BrandName = "Hugo Boss"
- },
- new Brand
- {
- BrandId = 0,
- BrandName = "Nike"
- }
- );
- context.Categories.AddRange(
- new Category
- {
- CategoryId = 0,
- CategoryName = "T-shirt"
- },
- new Category
- {
- CategoryId = 1,
- CategoryName = "Jacket"
- },
- new Category
- {
- CategoryId = 2,
- CategoryName = "Pants"
- },
- new Category
- {
- CategoryId = 3,
- CategoryName = "Shoes"
- }
- );
- context.Collections.AddRange(
- new Collection
- {
- CollectionId = 0,
- CollectionName = "Summer 2019"
- },
- new Collection
- {
- CollectionId = 1,
- CollectionName = "Spring 2018"
- },
- new Collection
- {
- CollectionId = 2,
- CollectionName = "Hugo Boss pants 2019"
- },
- new Collection
- {
- CollectionId = 3,
- CollectionName = "Airforce 1 2017"
- }
- );
- //context.SaveChanges();
- }
- context.SaveChanges();
- /*var pr1 = new Product
- // получаем объекты из бд и выводим на консоль
- /*var users = db.Products.ToList();
- Console.WriteLine("Users list:");
- foreach (Product u in users)
- {
- Console.WriteLine($"{u.Id} {u.Category} {u.Brand} {u.Collection} {u.ProductColor} {u.Amount}");
- }
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement