You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tp1Entity/tp1/TestStub/Program.cs

49 lines
1.3 KiB

using TestStub;
using Microsoft.Extensions.Options;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using (var context = new LibraryContext())
{
BookEntity chewie = new BookEntity("B3", "test1", "test1");
BookEntity yoda = new BookEntity ("B4", "test2", "test2");
BookEntity ewok = new BookEntity ("mistake", "test3", "test3");
BookEntity the100 = new BookEntity("the100", "test4", "test4");
context.BooksSet.Add(chewie);
context.BooksSet.Add(yoda);
context.BooksSet.Add(ewok);
context.BooksSet.Add(the100);
context.SaveChanges();
}
using (var context = new LibraryContext())
{
foreach (var n in context.BooksSet)
{
Console.WriteLine($"Books: {n.ID} - {n.Title}");
}
context.SaveChanges();
}
using (var context = new LibraryContext())
{
var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("t")).First();
Console.WriteLine($"{eBooks.Title} (made by {eBooks.Author})");
eBooks.Title = "Border";
context.SaveChanges();
}
using (var context = new LibraryContext())
{
Console.WriteLine("Deletes one item from de database");
var impostor = context.BooksSet
.SingleOrDefault(n => n.Title.Equals("mistake"));
context.Remove(impostor);
context.SaveChanges();
}