You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
771 B
Plaintext

@page "/"
@using EFCore7Study.DataService;
@using EFCore7Study.DataService.Models;
@using Microsoft.EntityFrameworkCore;
@inject IDbContextFactory<AppDbContext> DbFactory
<PageTitle>Index</PageTitle>
@foreach(var account in AccountList)
{
<h2>@(account.Name)</h2>
}
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
@code{
private List<Account> AccountList { get; set; } = new List<Account>();
protected override void OnInitialized()
{
AccountList = GetAccounts();
base.OnInitialized();
}
private List<Account> GetAccounts()
{
using (var context = DbFactory.CreateDbContext())
{
return context.Accounts.ToList();
};
}
}