Add entity framework #11

Merged
Egamorf merged 7 commits from release/entity-framework into main 2025-04-09 23:12:48 +02:00
5 changed files with 68 additions and 1 deletions
Showing only changes of commit cb60f3de31 - Show all commits

View File

@@ -0,0 +1,21 @@
namespace GameIdeas.Shared.Model;
public partial class Game
{
public Game()
{
GamePlatforms = new HashSet<GamePlatform>();
}
public int Id { get; set; }
public string Title { get; set; } = null!;
public DateTime? ReleaseDate { get; set; }
public DateTime CreationDate { get; set; }
public DateTime? ModificationDate { get; set; }
public double? StorageSpace { get; set; }
public string? Description { get; set; }
public int? Interest { get; set; }
public virtual ICollection<GamePlatform> GamePlatforms { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace GameIdeas.Shared.Model;
public partial class GamePlatform
{
public int GameId { get; set; }
public int PlatformId { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Platform Platform { get; set; } = null!;
}

View File

@@ -0,0 +1,8 @@
namespace GameIdeas.Shared.Model;
public partial class Platform
{
public int Id { get; set; }
public string Libelle { get; set; } = null!;
public string? Url { get; set; }
}

View File

@@ -0,0 +1,25 @@
using GameIdeas.Shared.Model;
using Microsoft.EntityFrameworkCore;
namespace GameIdeas.WebAPI.Context;
public class GameIdeasContext : DbContext
{
public GameIdeasContext(DbContextOptions<GameIdeasContext> option)
: base(option)
{ }
public virtual DbSet<Game> Games { get; set; } = null!;
public virtual DbSet<Platform> Platforms { get; set; } = null!;
public virtual DbSet<GamePlatform> GamePlatforms { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(@"Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
@@ -12,10 +12,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\GameIdeas.Resources\GameIdeas.Resources.csproj" /> <ProjectReference Include="..\..\GameIdeas.Resources\GameIdeas.Resources.csproj" />
<ProjectReference Include="..\..\GameIdeas.Shared\GameIdeas.Shared.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>