diff --git a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs b/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs
new file mode 100644
index 0000000..69346df
--- /dev/null
+++ b/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs
@@ -0,0 +1,47 @@
+//
+using DbContextLib;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace DbContextLib.Migrations
+{
+ [DbContext(typeof(LibraryContext))]
+ [Migration("20240201082456_BooksMigration")]
+ partial class BooksMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
+
+ modelBuilder.Entity("Entities.BookEntity", b =>
+ {
+ b.Property("ID")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Author")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Isbn")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("ID");
+
+ b.ToTable("BooksSet");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs b/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs
new file mode 100644
index 0000000..2e153c8
--- /dev/null
+++ b/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs
@@ -0,0 +1,36 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace DbContextLib.Migrations
+{
+ ///
+ public partial class BooksMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "BooksSet",
+ columns: table => new
+ {
+ ID = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Title = table.Column(type: "TEXT", nullable: false),
+ Author = table.Column(type: "TEXT", nullable: false),
+ Isbn = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BooksSet", x => x.ID);
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "BooksSet");
+ }
+ }
+}
diff --git a/tp1/DbContextLib/Migrations/LibraryContextModelSnapshot.cs b/tp1/DbContextLib/Migrations/LibraryContextModelSnapshot.cs
new file mode 100644
index 0000000..61df967
--- /dev/null
+++ b/tp1/DbContextLib/Migrations/LibraryContextModelSnapshot.cs
@@ -0,0 +1,44 @@
+//
+using DbContextLib;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace DbContextLib.Migrations
+{
+ [DbContext(typeof(LibraryContext))]
+ partial class LibraryContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
+
+ modelBuilder.Entity("Entities.BookEntity", b =>
+ {
+ b.Property("ID")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Author")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Isbn")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("ID");
+
+ b.ToTable("BooksSet");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/tp1/DbContextLib/tp1.Books.db b/tp1/DbContextLib/tp1.Books.db
new file mode 100644
index 0000000..0ba5d30
Binary files /dev/null and b/tp1/DbContextLib/tp1.Books.db differ
diff --git a/tp1/Library/DbContextLib/LibraryContext.cs b/tp1/Library/DbContextLib/LibraryContext.cs
index 5918c9d..853f9cc 100644
--- a/tp1/Library/DbContextLib/LibraryContext.cs
+++ b/tp1/Library/DbContextLib/LibraryContext.cs
@@ -15,7 +15,7 @@ namespace Library.DbContextLib
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
- optionsBuilder.UseSqlite($"Data Source=tp1.Books.db");
+ optionsBuilder.UseSqlite("Data Source=tp.Books.db");
}
}
diff --git a/tp1/Library/tp.Books.db b/tp1/Library/tp.Books.db
new file mode 100644
index 0000000..74136d8
Binary files /dev/null and b/tp1/Library/tp.Books.db differ
diff --git a/tp1/TestStub/BookEntity.cs b/tp1/TestStub/BookEntity.cs
new file mode 100644
index 0000000..a8bac3a
--- /dev/null
+++ b/tp1/TestStub/BookEntity.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TestStub
+{
+
+ public class BookEntity
+ {
+ public int ID { get; set; }
+ public string Title { get; set; }
+ public string Author { get; set; }
+ public string Isbn { get; set; }
+
+ public BookEntity(string title, string author, string isbn) {
+ Title = title;
+ Author = author;
+ Isbn = isbn;
+ }
+ }
+}
diff --git a/tp1/TestStub/LibraryContext.cs b/tp1/TestStub/LibraryContext.cs
new file mode 100644
index 0000000..450d9df
--- /dev/null
+++ b/tp1/TestStub/LibraryContext.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using Library.Entities;
+
+
+namespace TestStub
+{
+ public class LibraryContext : DbContext
+ {
+ public DbSet BooksSet { get; set; }
+
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ optionsBuilder.UseSqlite("Data Source=tp.Books.db");
+ }
+
+ }
+}
diff --git a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs b/tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs
new file mode 100644
index 0000000..c4db459
--- /dev/null
+++ b/tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs
@@ -0,0 +1,47 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using TestStub;
+
+#nullable disable
+
+namespace TestStub.Migrations
+{
+ [DbContext(typeof(LibraryContext))]
+ [Migration("20240201143359_BooksMigrations")]
+ partial class BooksMigrations
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
+
+ modelBuilder.Entity("TestStub.BookEntity", b =>
+ {
+ b.Property("ID")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Author")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Isbn")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("ID");
+
+ b.ToTable("BooksSet");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs b/tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs
new file mode 100644
index 0000000..1a50d42
--- /dev/null
+++ b/tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs
@@ -0,0 +1,36 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace TestStub.Migrations
+{
+ ///
+ public partial class BooksMigrations : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "BooksSet",
+ columns: table => new
+ {
+ ID = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Title = table.Column(type: "TEXT", nullable: false),
+ Author = table.Column(type: "TEXT", nullable: false),
+ Isbn = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BooksSet", x => x.ID);
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "BooksSet");
+ }
+ }
+}
diff --git a/tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs b/tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs
new file mode 100644
index 0000000..8c1c247
--- /dev/null
+++ b/tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs
@@ -0,0 +1,44 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using TestStub;
+
+#nullable disable
+
+namespace TestStub.Migrations
+{
+ [DbContext(typeof(LibraryContext))]
+ partial class LibraryContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
+
+ modelBuilder.Entity("TestStub.BookEntity", b =>
+ {
+ b.Property("ID")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Author")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Isbn")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("ID");
+
+ b.ToTable("BooksSet");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/tp1/TestStub/Program.cs b/tp1/TestStub/Program.cs
index 8a17720..7d494f6 100644
--- a/tp1/TestStub/Program.cs
+++ b/tp1/TestStub/Program.cs
@@ -1,6 +1,4 @@
-using Library;
-using Library.DbContextLib;
-using Library.Entities;
+using TestStub;
using Microsoft.Extensions.Options;
// See https://aka.ms/new-console-template for more information
@@ -8,13 +6,16 @@ Console.WriteLine("Hello, World!");
using (var context = new LibraryContext())
{
- BookEntity chewie = new BookEntity("B3", "test", "test2");
- BookEntity yoda = new BookEntity ("B4", "test", "test2");
- BookEntity ewok = new BookEntity ("C5", "test", "test3");
+ 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();
}
@@ -23,18 +24,26 @@ using (var context = new LibraryContext())
{
foreach (var n in context.BooksSet)
{
- Console.WriteLine($"{n.ID} - {n.Title}");
+ Console.WriteLine($"Books: {n.ID} - {n.Title}");
}
-
context.SaveChanges();
-
}
+
using (var context = new LibraryContext())
{
- var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("B")).First();
- Console.WriteLine($"{eBooks.Title} (born in {eBooks.Author})");
+ var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("t")).First();
+ 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();
+
}
\ No newline at end of file
diff --git a/tp1/TestStub/StubbedContext.cs b/tp1/TestStub/StubbedContext.cs
new file mode 100644
index 0000000..f397ada
--- /dev/null
+++ b/tp1/TestStub/StubbedContext.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Library.DbContextLib;
+using Library.Entities;
+using Microsoft.EntityFrameworkCore;
+
+namespace TestStub
+{
+ public class StubbedContext : DbContext
+ {
+ public List Books { get; set; }
+
+ public StubbedContext() {
+ Books.Add(new BookEntity("test", "test", "test"));
+ Books.Add(new BookEntity("test2", "test2", "test2"));
+ }
+
+ }
+}
diff --git a/tp1/TestStub/tp.Books.db b/tp1/TestStub/tp.Books.db
new file mode 100644
index 0000000..9b976f7
Binary files /dev/null and b/tp1/TestStub/tp.Books.db differ
diff --git a/tp1/TestStubEF/Class1.cs b/tp1/TestStubEF/Class1.cs
deleted file mode 100644
index 7e68d8e..0000000
--- a/tp1/TestStubEF/Class1.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace TestStubEF
-{
- public class Class1
- {
-
- }
-}
diff --git a/tp1/TestStubEF/TestStubEF.csproj b/tp1/TestStubEF/TestStubEF.csproj
deleted file mode 100644
index bb23fb7..0000000
--- a/tp1/TestStubEF/TestStubEF.csproj
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- net8.0
- enable
- enable
-
-
-
diff --git a/tp1/tp1/Program.cs b/tp1/tp1/Program.cs
deleted file mode 100644
index bb851ad..0000000
--- a/tp1/tp1/Program.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-using Microsoft.EntityFrameworkCore.Design;
-
-// See https://aka.ms/new-console-template for more information
-Console.WriteLine("Hello, World!");
diff --git a/tp1/tp1/TestStubEF.csproj b/tp1/tp1/TestStubEF.csproj
deleted file mode 100644
index e4b7805..0000000
--- a/tp1/tp1/TestStubEF.csproj
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
- Exe
- net8.0
- enable
- enable
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
-