diff --git a/tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs deleted file mode 100644 index bb016fa..0000000 --- a/tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubbedContext))] - [Migration("20240209013745_Mg")] - partial class Mg - { - /// - 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/StubbedContextLib/Migrations/20240209013745_Mg.cs b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.cs deleted file mode 100644 index 9ac614b..0000000 --- a/tp1/StubbedContextLib/Migrations/20240209013745_Mg.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class Mg : 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/StubbedContextLib/Migrations/20240209155948_Mg.Designer.cs b/tp1/StubbedContextLib/Migrations/20240209155948_Mg.Designer.cs new file mode 100644 index 0000000..154b565 --- /dev/null +++ b/tp1/StubbedContextLib/Migrations/20240209155948_Mg.Designer.cs @@ -0,0 +1,89 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubbedContext))] + [Migration("20240209155948_Mg")] + partial class Mg + { + /// + 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("OwnerId") + .HasColumnType("INTEGER"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("ID"); + + b.HasIndex("OwnerId"); + + b.ToTable("BooksSet"); + }); + + modelBuilder.Entity("Entities.PersonEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PersonSet"); + }); + + modelBuilder.Entity("Entities.BookEntity", b => + { + b.HasOne("Entities.PersonEntity", "Owner") + .WithMany("Books") + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Entities.PersonEntity", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/tp1/StubbedContextLib/Migrations/20240209155948_Mg.cs b/tp1/StubbedContextLib/Migrations/20240209155948_Mg.cs new file mode 100644 index 0000000..f03f257 --- /dev/null +++ b/tp1/StubbedContextLib/Migrations/20240209155948_Mg.cs @@ -0,0 +1,65 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class Mg : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "PersonSet", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + FirstName = table.Column(type: "TEXT", nullable: false), + LastName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PersonSet", x => x.Id); + }); + + 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), + PersonId = table.Column(type: "INTEGER", nullable: false), + OwnerId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_BooksSet", x => x.ID); + table.ForeignKey( + name: "FK_BooksSet_PersonSet_OwnerId", + column: x => x.OwnerId, + principalTable: "PersonSet", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_BooksSet_OwnerId", + table: "BooksSet", + column: "OwnerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "BooksSet"); + + migrationBuilder.DropTable( + name: "PersonSet"); + } + } +} diff --git a/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs b/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs index 1454cd1..3e7e88c 100644 --- a/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs +++ b/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs @@ -1,44 +1,86 @@ -// -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubbedContext))] - partial class StubbedContextModelSnapshot : 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 - } - } -} +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubbedContext))] + partial class StubbedContextModelSnapshot : 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("OwnerId") + .HasColumnType("INTEGER"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("ID"); + + b.HasIndex("OwnerId"); + + b.ToTable("BooksSet"); + }); + + modelBuilder.Entity("Entities.PersonEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("PersonSet"); + }); + + modelBuilder.Entity("Entities.BookEntity", b => + { + b.HasOne("Entities.PersonEntity", "Owner") + .WithMany("Books") + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Entities.PersonEntity", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/tp1/StubbedContextLib/StubbedContext.cs b/tp1/StubbedContextLib/StubbedContext.cs index 418364f..4f79e00 100644 --- a/tp1/StubbedContextLib/StubbedContext.cs +++ b/tp1/StubbedContextLib/StubbedContext.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,8 +16,14 @@ namespace StubbedContextLib public List Books { get; set; } = new List(); public StubbedContext() { - Books.Add(new BookEntity("test", "test", "test")); - Books.Add(new BookEntity("test2", "test2", "test2")); + BookEntity b0 = new BookEntity() { Title = "test", Author = "test", Isbn = "test" }; + BookEntity b1 = new BookEntity() { Title = "test2", Author = "test2", Isbn = "test2" }; + Books.Add(b0); + Books.Add(b1); + Collection CB = new Collection(); + CB.Add(b0); + CB.Add(b1); + Persons.Add(new PersonEntity() { FirstName = "coco", LastName = "test", Books = CB }); } }