Added n -> m relation support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
@page "/"
|
||||
@using HopFrame.Testing.Models
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbCont
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
.HasOne<User>()
|
||||
.WithMany()
|
||||
.HasOne<User>(p => p.Author)
|
||||
.WithMany(u => u.Posts)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class Post {
|
||||
[MaxLength(255)]
|
||||
public required string Caption { get; set; }
|
||||
|
||||
public required string Content { get; set; }
|
||||
public required string? Content { get; set; }
|
||||
|
||||
[ForeignKey("author")]
|
||||
public virtual required User Author { get; set; }
|
||||
|
||||
@@ -11,6 +11,8 @@ public class User {
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public virtual List<Post> Posts { get; set; } = new();
|
||||
|
||||
public override string ToString() {
|
||||
return Username;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using HopFrame.Testing;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using HopFrame.Testing.Components;
|
||||
@@ -41,6 +42,9 @@ builder.Services.AddHopFrame(options => {
|
||||
table.SetDescription("This table is used for user data store and user authentication");
|
||||
|
||||
table.SetViewPolicy("policy");
|
||||
|
||||
table.Property(u => u.Posts)
|
||||
.FormatEach<Post>(post => post.Caption);
|
||||
});
|
||||
|
||||
context.Table<Post>()
|
||||
@@ -56,7 +60,7 @@ builder.Services.AddHopFrame(options => {
|
||||
|
||||
context.Table<Post>()
|
||||
.Property(p => p.Caption)
|
||||
.Validator(input => {
|
||||
/*.Validator(input => {
|
||||
var errors = new List<string>();
|
||||
|
||||
if (input is null)
|
||||
@@ -66,7 +70,7 @@ builder.Services.AddHopFrame(options => {
|
||||
errors.Add("Value can only be 10 characters long");
|
||||
|
||||
return errors;
|
||||
});
|
||||
})*/;
|
||||
|
||||
context.Table<Post>()
|
||||
.OrderIndex(-1);
|
||||
|
||||
Reference in New Issue
Block a user