diff --git a/tp1/DbContextLib/LibraryContext.cs b/tp1/DbContextLib/LibraryContext.cs index 1f8d92e..883f51b 100644 --- a/tp1/DbContextLib/LibraryContext.cs +++ b/tp1/DbContextLib/LibraryContext.cs @@ -1,21 +1,23 @@ -using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Entities; + namespace DbContextLib { - - public class LibraryContext: DbContext + public class LibraryContext : DbContext { - public DbSet BooksSet{ get; set; } + public DbSet PersonSet { get; set; } + public DbSet BooksSet { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite($"Data Source=tp1.Books.db"); + optionsBuilder.UseSqlite("Data Source=tp.Books.db"); } } - } - - - diff --git a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs b/tp1/DbContextLib/Migrations/20240209010818_Mg.Designer.cs similarity index 94% rename from tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs rename to tp1/DbContextLib/Migrations/20240209010818_Mg.Designer.cs index 69346df..36c19de 100644 --- a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.Designer.cs +++ b/tp1/DbContextLib/Migrations/20240209010818_Mg.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace DbContextLib.Migrations { [DbContext(typeof(LibraryContext))] - [Migration("20240201082456_BooksMigration")] - partial class BooksMigration + [Migration("20240209010818_Mg")] + partial class Mg { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs b/tp1/DbContextLib/Migrations/20240209010818_Mg.cs similarity index 95% rename from tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs rename to tp1/DbContextLib/Migrations/20240209010818_Mg.cs index 2e153c8..0ce9e15 100644 --- a/tp1/DbContextLib/Migrations/20240201082456_BooksMigration.cs +++ b/tp1/DbContextLib/Migrations/20240209010818_Mg.cs @@ -5,7 +5,7 @@ namespace DbContextLib.Migrations { /// - public partial class BooksMigration : Migration + public partial class Mg : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/tp1/DbContextLib/tp1.Books.db b/tp1/DbContextLib/tp1.Books.db deleted file mode 100644 index 0ba5d30..0000000 Binary files a/tp1/DbContextLib/tp1.Books.db and /dev/null differ diff --git a/tp1/Entities/BookEntity.cs b/tp1/Entities/BookEntity.cs index 3cde984..01711d6 100644 --- a/tp1/Entities/BookEntity.cs +++ b/tp1/Entities/BookEntity.cs @@ -1,13 +1,25 @@ -using System.Reflection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace Entities { + public class BookEntity { - - public int ID {get; set;} + public int ID { get; set; } public string Title { get; set; } public string Author { get; set; } public string Isbn { get; set; } + + public PersonEntity? Person { get; set; } + + public BookEntity(string title, string author, string isbn) { + Title = title; + Author = author; + Isbn = isbn; + } } } diff --git a/tp1/Entities/Entities.csproj b/tp1/Entities/Entities.csproj index 0c79874..bb23fb7 100644 --- a/tp1/Entities/Entities.csproj +++ b/tp1/Entities/Entities.csproj @@ -6,17 +6,4 @@ enable - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/tp1/Entities/PersonEntity.cs b/tp1/Entities/PersonEntity.cs new file mode 100644 index 0000000..5f0e45c --- /dev/null +++ b/tp1/Entities/PersonEntity.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entities +{ + public class PersonEntity + { + public long Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + + public ICollection Books { get; set; } + + } +} diff --git a/tp1/Library/DbContextLib/LibraryContext.cs b/tp1/Library/DbContextLib/LibraryContext.cs deleted file mode 100644 index 853f9cc..0000000 --- a/tp1/Library/DbContextLib/LibraryContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Library.Entities; - - -namespace Library.DbContextLib -{ - 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/Library/Entities/BookEntity.cs b/tp1/Library/Entities/BookEntity.cs deleted file mode 100644 index 4ecea42..0000000 --- a/tp1/Library/Entities/BookEntity.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Library.Entities -{ - 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/Library/Library.csproj b/tp1/Library/Library.csproj deleted file mode 100644 index 0c79874..0000000 --- a/tp1/Library/Library.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/tp1/Library/StubbedContextLib/StubbedContext.cs b/tp1/Library/StubbedContextLib/StubbedContext.cs deleted file mode 100644 index 4474e2b..0000000 --- a/tp1/Library/StubbedContextLib/StubbedContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -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 Library.StubbedContextLib -{ - 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/Library/tp.Books.db b/tp1/Library/tp.Books.db deleted file mode 100644 index 74136d8..0000000 Binary files a/tp1/Library/tp.Books.db and /dev/null differ diff --git a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs similarity index 83% rename from tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs rename to tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs index c4db459..bb016fa 100644 --- a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.Designer.cs +++ b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.Designer.cs @@ -3,15 +3,15 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TestStub; +using StubbedContextLib; #nullable disable -namespace TestStub.Migrations +namespace StubbedContextLib.Migrations { - [DbContext(typeof(LibraryContext))] - [Migration("20240201143359_BooksMigrations")] - partial class BooksMigrations + [DbContext(typeof(StubbedContext))] + [Migration("20240209013745_Mg")] + partial class Mg { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -19,7 +19,7 @@ namespace TestStub.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); - modelBuilder.Entity("TestStub.BookEntity", b => + modelBuilder.Entity("Entities.BookEntity", b => { b.Property("ID") .ValueGeneratedOnAdd() diff --git a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.cs similarity index 92% rename from tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs rename to tp1/StubbedContextLib/Migrations/20240209013745_Mg.cs index 1a50d42..9ac614b 100644 --- a/tp1/TestStub/Migrations/20240201143359_BooksMigrations.cs +++ b/tp1/StubbedContextLib/Migrations/20240209013745_Mg.cs @@ -2,10 +2,10 @@ #nullable disable -namespace TestStub.Migrations +namespace StubbedContextLib.Migrations { /// - public partial class BooksMigrations : Migration + public partial class Mg : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs b/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs similarity index 82% rename from tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs rename to tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs index 8c1c247..1454cd1 100644 --- a/tp1/TestStub/Migrations/LibraryContextModelSnapshot.cs +++ b/tp1/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs @@ -2,21 +2,21 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using TestStub; +using StubbedContextLib; #nullable disable -namespace TestStub.Migrations +namespace StubbedContextLib.Migrations { - [DbContext(typeof(LibraryContext))] - partial class LibraryContextModelSnapshot : ModelSnapshot + [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("TestStub.BookEntity", b => + modelBuilder.Entity("Entities.BookEntity", b => { b.Property("ID") .ValueGeneratedOnAdd() diff --git a/tp1/StubbedContextLib/StubbedContext.cs b/tp1/StubbedContextLib/StubbedContext.cs index b2e65bd..418364f 100644 --- a/tp1/StubbedContextLib/StubbedContext.cs +++ b/tp1/StubbedContextLib/StubbedContext.cs @@ -1,11 +1,23 @@ -using Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DbContextLib; +using Entities; using Microsoft.EntityFrameworkCore; namespace StubbedContextLib { - public class StubbedContext : DbContext + public class StubbedContext : LibraryContext { + public List Persons { get; set; } = new List(); + public List Books { get; set; } = new List(); + public StubbedContext() { + Books.Add(new BookEntity("test", "test", "test")); + Books.Add(new BookEntity("test2", "test2", "test2")); + } } } diff --git a/tp1/StubbedContextLib/StubbedContextLib.csproj b/tp1/StubbedContextLib/StubbedContextLib.csproj index e9bc770..1ad28e9 100644 --- a/tp1/StubbedContextLib/StubbedContextLib.csproj +++ b/tp1/StubbedContextLib/StubbedContextLib.csproj @@ -19,9 +19,9 @@ - + diff --git a/tp1/TestStub/BookEntity.cs b/tp1/TestStub/BookEntity.cs deleted file mode 100644 index a8bac3a..0000000 --- a/tp1/TestStub/BookEntity.cs +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 450d9df..0000000 --- a/tp1/TestStub/LibraryContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/Program.cs b/tp1/TestStub/Program.cs index 7d494f6..b2de216 100644 --- a/tp1/TestStub/Program.cs +++ b/tp1/TestStub/Program.cs @@ -1,4 +1,6 @@ -using TestStub; +using StubbedContextLib; +using Entities; +using DbContextLib; using Microsoft.Extensions.Options; // See https://aka.ms/new-console-template for more information diff --git a/tp1/TestStub/StubbedContext.cs b/tp1/TestStub/StubbedContext.cs deleted file mode 100644 index f397ada..0000000 --- a/tp1/TestStub/StubbedContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/TestStub.csproj b/tp1/TestStub/TestStub.csproj index 546f891..967153c 100644 --- a/tp1/TestStub/TestStub.csproj +++ b/tp1/TestStub/TestStub.csproj @@ -22,7 +22,9 @@ - + + + diff --git a/tp1/TestStub/tp.Books.db b/tp1/TestStub/tp.Books.db index 9b976f7..e005c58 100644 Binary files a/tp1/TestStub/tp.Books.db and b/tp1/TestStub/tp.Books.db differ diff --git a/tp1/tp1.sln b/tp1/tp1.sln index a0c64a8..0d2e984 100644 --- a/tp1/tp1.sln +++ b/tp1/tp1.sln @@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStub", "TestStub\TestStub.csproj", "{8960D74C-259D-4779-80B6-789BA257D2B2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestStub", "TestStub\TestStub.csproj", "{8960D74C-259D-4779-80B6-789BA257D2B2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "Library\Library.csproj", "{CDD5A87A-187A-4BC1-9E23-5559A2211B55}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{A4130190-8883-42DE-89CA-3DF205DE710A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F793C071-E178-48D3-BBE6-22F99D102C2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{5C673F26-2E43-4AA8-944E-1A3B309927CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +21,18 @@ Global {8960D74C-259D-4779-80B6-789BA257D2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.Build.0 = Release|Any CPU - {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.Build.0 = Release|Any CPU + {A4130190-8883-42DE-89CA-3DF205DE710A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4130190-8883-42DE-89CA-3DF205DE710A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4130190-8883-42DE-89CA-3DF205DE710A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4130190-8883-42DE-89CA-3DF205DE710A}.Release|Any CPU.Build.0 = Release|Any CPU + {F793C071-E178-48D3-BBE6-22F99D102C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F793C071-E178-48D3-BBE6-22F99D102C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F793C071-E178-48D3-BBE6-22F99D102C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F793C071-E178-48D3-BBE6-22F99D102C2B}.Release|Any CPU.Build.0 = Release|Any CPU + {5C673F26-2E43-4AA8-944E-1A3B309927CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C673F26-2E43-4AA8-944E-1A3B309927CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C673F26-2E43-4AA8-944E-1A3B309927CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C673F26-2E43-4AA8-944E-1A3B309927CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE