|
|
@ -1,6 +1,4 @@
|
|
|
|
using Library;
|
|
|
|
using TestStub;
|
|
|
|
using Library.DbContextLib;
|
|
|
|
|
|
|
|
using Library.Entities;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
@ -8,13 +6,16 @@ Console.WriteLine("Hello, World!");
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BookEntity chewie = new BookEntity("B3", "test", "test2");
|
|
|
|
BookEntity chewie = new BookEntity("B3", "test1", "test1");
|
|
|
|
BookEntity yoda = new BookEntity ("B4", "test", "test2");
|
|
|
|
BookEntity yoda = new BookEntity ("B4", "test2", "test2");
|
|
|
|
BookEntity ewok = new BookEntity ("C5", "test", "test3");
|
|
|
|
BookEntity ewok = new BookEntity ("mistake", "test3", "test3");
|
|
|
|
|
|
|
|
BookEntity the100 = new BookEntity("the100", "test4", "test4");
|
|
|
|
|
|
|
|
|
|
|
|
context.BooksSet.Add(chewie);
|
|
|
|
context.BooksSet.Add(chewie);
|
|
|
|
context.BooksSet.Add(yoda);
|
|
|
|
context.BooksSet.Add(yoda);
|
|
|
|
context.BooksSet.Add(ewok);
|
|
|
|
context.BooksSet.Add(ewok);
|
|
|
|
|
|
|
|
context.BooksSet.Add(the100);
|
|
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -23,18 +24,26 @@ using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var n in context.BooksSet)
|
|
|
|
foreach (var n in context.BooksSet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine($"{n.ID} - {n.Title}");
|
|
|
|
Console.WriteLine($"Books: {n.ID} - {n.Title}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("B")).First();
|
|
|
|
var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("t")).First();
|
|
|
|
Console.WriteLine($"{eBooks.Title} (born in {eBooks.Author})");
|
|
|
|
Console.WriteLine($"{eBooks.Title} (made by {eBooks.Author})");
|
|
|
|
|
|
|
|
eBooks.Title = "Border";
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
eBooks.Title = "Wicket";
|
|
|
|
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();
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|