Added relation support
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@page "/"
|
||||
@using HopFrame.Testing.Models
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
@@ -11,20 +12,32 @@ Welcome to your new Fluent Blazor app.
|
||||
@code {
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
User? user = null;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
var first = GenerateName(Random.Shared.Next(4, 6));
|
||||
var last = GenerateName(Random.Shared.Next(4, 6));
|
||||
var username = $"{first}.{last}";
|
||||
Context.Users.Add(new() {
|
||||
|
||||
user = new() {
|
||||
Email = $"{username}-{Random.Shared.Next(0, 20)}@gmail.com",
|
||||
Id = Guid.CreateVersion7(),
|
||||
FirstName = first,
|
||||
LastName = last,
|
||||
Username = username
|
||||
});
|
||||
};
|
||||
|
||||
Context.Users.Add(user);
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
Context.Posts.Add(new() {
|
||||
Caption = "Cool Post",
|
||||
Content = "This post is cool",
|
||||
Author = user
|
||||
});
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public static string GenerateName(int len) {
|
||||
@@ -46,3 +59,5 @@ Welcome to your new Fluent Blazor app.
|
||||
}
|
||||
|
||||
}
|
||||
using HopFrame.Testing.Models;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace HopFrame.Testing.Models;
|
||||
|
||||
public class Post {
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[MaxLength(255)]
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace HopFrame.Testing.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace HopFrame.Testing.Models;
|
||||
|
||||
public class User {
|
||||
[Key]
|
||||
public required Guid Id { get; init; }
|
||||
public required string Email { get; init; }
|
||||
public string? Username { get; set; }
|
||||
|
||||
@@ -35,6 +35,10 @@ builder.Services.AddHopFrame(options => {
|
||||
table.Property(u => u.Id)
|
||||
.Sortable(false);
|
||||
});
|
||||
|
||||
context.Table<Post>()
|
||||
.Property(p => p.Author)
|
||||
.DisplayedProperty(u => u!.Username);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user