Added ef core integration
All checks were successful
HopFrame CI / build (push) Successful in 46s
HopFrame CI / test (push) Successful in 50s

This commit is contained in:
2026-02-23 16:20:32 +01:00
parent e8ac7eb88a
commit 6730d57771
25 changed files with 929 additions and 63 deletions

View File

@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using TestApplication.Models;
namespace TestApplication;
public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options) {
public DbSet<User> Users { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>()
.HasMany(u => u.Posts)
.WithOne(p => p.Sender)
.OnDelete(DeleteBehavior.Cascade);
}
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace TestApplication.Models;
public class Post {
[Key]
public Guid Id { get; } = Guid.CreateVersion7();
public required User Sender { get; set; }
[MaxLength(5000)]
public required string Message { get; set; }
}

View File

@@ -0,0 +1,30 @@
using System.ComponentModel.DataAnnotations;
namespace TestApplication.Models;
public class User {
[Key]
public Guid Id { get; } = Guid.CreateVersion7();
[EmailAddress, MaxLength(25)]
public required string Email { get; set; }
[MaxLength(25)]
public required string Username { get; set; }
[MaxLength(64)]
public required string Password { get; set; }
[MaxLength(25)]
public required string FirstName { get; set; }
[MaxLength(25)]
public required string LastName { get; set; }
[MaxLength(255)]
public string? Description { get; set; }
public required DateOnly Birth { get; set; } = DateOnly.FromDateTime(DateTime.Today);
public List<Post> Posts { get; set; } = new();
}

View File

@@ -1,3 +1,7 @@
using HopFrame.Core;
using HopFrame.Core.EFCore;
using Microsoft.EntityFrameworkCore;
using TestApplication;
using TestApplication.Components;
var builder = WebApplication.CreateBuilder(args);
@@ -6,6 +10,15 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddEntityFrameworkInMemoryDatabase();
builder.Services.AddDbContext<DatabaseContext>(options => {
options.UseInMemoryDatabase("testing");
});
builder.Services.AddHopFrame(config => {
config.AddDbContext<DatabaseContext>();
});
var app = builder.Build();
// Configure the HTTP request pipeline.

View File

@@ -4,7 +4,7 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5281",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -13,7 +13,7 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7126;http://localhost:5281",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"

View File

@@ -11,4 +11,8 @@
<ProjectReference Include="..\..\src\HopFrame.Core\HopFrame.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.3" />
</ItemGroup>
</Project>