Probleme Compris besions d'initialiser context🚧

testTony
Tony Fages 1 year ago
parent 7afe33c430
commit 25712e7513

@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
@ -12,12 +13,17 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API_DbDataManager\API_DbDataManager.csproj" />
<ProjectReference Include="..\API_Services\API_Services.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup>
</Project>

@ -17,6 +17,8 @@ builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<LibraryContext>();
builder.Services.AddScoped<IArticleService, DbManagerArticle>();
builder.Services.AddScoped<IUserService, DbManagerUser>();
builder.Services.AddScoped<IFormulaireService, DbManagerFormulaire>();
var app = builder.Build();

@ -5,11 +5,22 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DbDataManager</RootNamespace>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\API_Services\API_Services.csproj" />
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,12 @@
using DbContextLib;
namespace DbDataManager;
public class DbManager
{
protected LibraryContext _context;
public DbManager()
{
_context = new LibraryContext();
}
}

@ -11,7 +11,7 @@ public class DbManagerArticle : IArticleService
public DbManagerArticle(LibraryContext context)
{
_context = context;
_context = new LibraryContext();
}
public async Task<Article?> CreateArticle(long id, string title, string description, string author, string date, int lectureTime)
@ -34,6 +34,7 @@ public class DbManagerArticle : IArticleService
public async Task<Article?> 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<IEnumerable<Article?>> GetAllArticles()
{
Console.WriteLine("GetAllArticles");
return await Task.FromResult(_context.ArticleSet.Select(a => a.ToModel()).AsEnumerable());
}
}

@ -10,7 +10,7 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
[Migration("20240305073325_mrg1")]
[Migration("20240307182411_mrg1")]
partial class mrg1
{
/// <inheritdoc />
@ -149,7 +149,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("UserEntityId");
b.ToTable("FormEntity");
b.ToTable("FormSet");
});
modelBuilder.Entity("Entities.UserEntity", b =>

@ -72,7 +72,7 @@ namespace StubbedContextLib.Migrations
});
migrationBuilder.CreateTable(
name: "FormEntity",
name: "FormSet",
columns: table => new
{
Id = table.Column<long>(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");

@ -146,7 +146,7 @@ namespace StubbedContextLib.Migrations
b.HasIndex("UserEntityId");
b.ToTable("FormEntity");
b.ToTable("FormSet");
});
modelBuilder.Entity("Entities.UserEntity", b =>

Loading…
Cancel
Save