static void Main(string[] args)
        {
            FruitContext context = new FruitContext();

            //context.Database.EnsureCreated();

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            //INSERT
            var f1 = new Fruit
            {
                name  = "Äpple",
                color = "lila"
            };

            context.Fruits.Add(f1);
            context.SaveChanges();



            //SELECT
            foreach (var fruit in context.Fruits)
            {
                Console.WriteLine(fruit.fruitId.ToString().PadRight(10) + fruit.name.PadRight(15) + fruit.color.PadRight(10));
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            FruitContext context = new FruitContext();
            //context.Database.EnsureDeleted();

            //context.Database.EnsureCreated();

            var newfruit = new Fruit
            {
                Name  = "Banan",
                Color = "Gul"
            };

            context.Fruits.Add(newfruit);
            context.Fruits.Add(new Fruit {
                Name = "Apple", Color = "Red"
            });
            context.SaveChanges();

            //context.Fruits
            foreach (Fruit x in  context.Fruits)
            {
                Console.WriteLine(x.Id + " " + x.Name + " " + x.Color);
            }
        }
示例#3
0
        static void Main()
        {
            FruitContext _context = new FruitContext();

            //_context.Database.EnsureDeleted();
            //_context.Database.EnsureCreated(); // Använder inte migrationer för att uppdatera databasen. Kan inte senare uppdatera databasen mha migrationer

            _context.Fruits.Add(new Fruit {
                Name = "Banan"
            });
            _context.SaveChanges();

            foreach (Fruit x in _context.Fruits)
            {
                Console.WriteLine(x.Id + "  " + x.Name);
            }

            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            FruitContext context = new FruitContext();

            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated();


            context.Fruits.Add(new Fruit {
                Name = "Äpple", Color = "Rött"
            });

            context.SaveChanges();

            foreach (Fruit item in context.Fruits)
            {
                Console.WriteLine(item.Id + "  " + item.Name + " " + item.Color);
            }
        }
示例#5
0
        static void Main()
        {
            FruitContext context = new FruitContext();

            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated(); // Använder inte migrationer för att uppdatera databasen. Kan inte senare uppdatera databasen mha migrationer

            //// Här görs en INSERT
            context.Fruits.Add(new Fruit {
                Name = "Äpple", Color = "Rött"
            });
            context.SaveChanges();

            //// Här görs en SELECT
            foreach (Fruit x in context.Fruits)
            {
                Console.WriteLine(x.Id + "  " + x.Name + "  " + x.Color);
            }

            Console.ReadKey();
        }
示例#6
0
        static void Main(string[] args)
        {
            FruitContext context = new FruitContext();

            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated();

            context.Fruits.Add(new Fruit {
                Name = "Äpple", Color = "Rött"
            });

            foreach (var item in context.Fruits)
            {
                Console.WriteLine(item.Id + " " + item.Name + " " + item.Color);
            }

            //var newfruit = new Fruit
            //{
            //    Name = "Banan"
            //};

            //context.Fruits.Add(newfruit);
            context.SaveChanges();
        }