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)); } }
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); } }
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(); }
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); } }
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(); }
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(); }