From 25712e751367921aa56c0d0cf53a42cc10e04834 Mon Sep 17 00:00:00 2001 From: tonyfages Date: Thu, 7 Mar 2024 20:10:06 +0100 Subject: [PATCH] =?UTF-8?q?Probleme=20Compris=20besions=20d'initialiser=20?= =?UTF-8?q?context=F0=9F=9A=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Verax_API_EF/API/API.csproj | 6 ++++++ Verax_API_EF/API/Program.cs | 2 ++ .../API_DbDataManager.csproj | 11 +++++++++++ Verax_API_EF/API_DbDataManager/DbManager.cs | 12 ++++++++++++ .../API_DbDataManager/DbManagerArticle.cs | 4 +++- .../Entity_FrameWork.Article.db | Bin 45056 -> 45056 bytes .../Entity_FrameWork.Article.db-shm | Bin 0 -> 32768 bytes .../Entity_FrameWork.Article.db-wal | 0 ...ner.cs => 20240307182411_mrg1.Designer.cs} | 4 ++-- ...5073325_mrg1.cs => 20240307182411_mrg1.cs} | 12 ++++++------ .../Migrations/StubbedContextModelSnapshot.cs | 2 +- 11 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 Verax_API_EF/API_DbDataManager/DbManager.cs rename Verax_API_EF/{Test_Console_EF => API_DbDataManager}/Entity_FrameWork.Article.db (97%) create mode 100644 Verax_API_EF/API_DbDataManager/Entity_FrameWork.Article.db-shm create mode 100644 Verax_API_EF/API_DbDataManager/Entity_FrameWork.Article.db-wal rename Verax_API_EF/StubbedContextLib/Migrations/{20240305073325_mrg1.Designer.cs => 20240307182411_mrg1.Designer.cs} (99%) rename Verax_API_EF/StubbedContextLib/Migrations/{20240305073325_mrg1.cs => 20240307182411_mrg1.cs} (95%) diff --git a/Verax_API_EF/API/API.csproj b/Verax_API_EF/API/API.csproj index 8e60ffc..8632b39 100644 --- a/Verax_API_EF/API/API.csproj +++ b/Verax_API_EF/API/API.csproj @@ -5,6 +5,7 @@ enable enable true + $(MSBuildProjectDirectory) @@ -12,12 +13,17 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Verax_API_EF/API/Program.cs b/Verax_API_EF/API/Program.cs index d07947c..4b93a95 100644 --- a/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/API/Program.cs @@ -17,6 +17,8 @@ builder.Services.AddSwaggerGen(); builder.Services.AddDbContext(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj index 098d5a6..a020201 100644 --- a/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj +++ b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj @@ -5,11 +5,22 @@ enable enable DbDataManager + $(MSBuildProjectDirectory) + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Verax_API_EF/API_DbDataManager/DbManager.cs b/Verax_API_EF/API_DbDataManager/DbManager.cs new file mode 100644 index 0000000..6e4990b --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/DbManager.cs @@ -0,0 +1,12 @@ +using DbContextLib; + +namespace DbDataManager; + +public class DbManager +{ + protected LibraryContext _context; + public DbManager() + { + _context = new LibraryContext(); + } +} \ No newline at end of file diff --git a/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs b/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs index 9d0d2fa..ca98ae5 100644 --- a/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs +++ b/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs @@ -11,7 +11,7 @@ public class DbManagerArticle : IArticleService public DbManagerArticle(LibraryContext context) { - _context = context; + _context = new LibraryContext(); } public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) @@ -34,6 +34,7 @@ public class DbManagerArticle : IArticleService public async Task DeleteArticle(long id) { var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); + Console.WriteLine(entity); if (entity == null) return null; _context.ArticleSet.Remove(entity); await _context.SaveChangesAsync(); @@ -61,6 +62,7 @@ public class DbManagerArticle : IArticleService public async Task> GetAllArticles() { + Console.WriteLine("GetAllArticles"); return await Task.FromResult(_context.ArticleSet.Select(a => a.ToModel()).AsEnumerable()); } } \ No newline at end of file diff --git a/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/API_DbDataManager/Entity_FrameWork.Article.db similarity index 97% rename from Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db rename to Verax_API_EF/API_DbDataManager/Entity_FrameWork.Article.db index 18350873d4552aa83d40d78e16e90841abc2ca4d..becbb82ace3aec72d172dff2174e0573bf444e47 100644 GIT binary patch delta 269 zcmZp8z|`=7X+oBmDFfeC{B(YzYLkz1tYHSa zXL1jB^5#37!eZ>^h89L9hK8HJ$^YY*f^y<>i_#5w85kIt`OY!$Pvtk_I|uaM0lv-W N> @@ -149,7 +149,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("FormEntity"); + b.ToTable("FormSet"); }); modelBuilder.Entity("Entities.UserEntity", b => diff --git a/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs b/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs similarity index 95% rename from Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs rename to Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs index 7cfb904..a40c540 100644 --- a/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs +++ b/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs @@ -72,7 +72,7 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.CreateTable( - name: "FormEntity", + name: "FormSet", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) @@ -85,9 +85,9 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_FormEntity", x => x.Id); + table.PrimaryKey("PK_FormSet", x => x.Id); table.ForeignKey( - name: "FK_FormEntity_UserSet_UserEntityId", + name: "FK_FormSet_UserSet_UserEntityId", column: x => x.UserEntityId, principalTable: "UserSet", principalColumn: "Id", @@ -132,8 +132,8 @@ namespace StubbedContextLib.Migrations column: "UserEntityId"); migrationBuilder.CreateIndex( - name: "IX_FormEntity_UserEntityId", - table: "FormEntity", + name: "IX_FormSet_UserEntityId", + table: "FormSet", column: "UserEntityId"); } @@ -144,7 +144,7 @@ namespace StubbedContextLib.Migrations name: "ArticleUserEntity"); migrationBuilder.DropTable( - name: "FormEntity"); + name: "FormSet"); migrationBuilder.DropTable( name: "ArticleSet"); diff --git a/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs b/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs index 46de8e6..c4e950b 100644 --- a/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs +++ b/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs @@ -146,7 +146,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("FormEntity"); + b.ToTable("FormSet"); }); modelBuilder.Entity("Entities.UserEntity", b =>