Skip to content

Commit a012ef6

Browse files
committed
Add project files.
1 parent 105e7b0 commit a012ef6

File tree

13 files changed

+281
-0
lines changed

13 files changed

+281
-0
lines changed

EntityFrameworkBlazorWasmNET8.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34728.123
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkInFrontend", "EntityFrameworkInFrontend\EntityFrameworkInFrontend.csproj", "{E4C9D52E-2230-4C84-986C-04D797C39952}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E4C9D52E-2230-4C84-986C-04D797C39952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E4C9D52E-2230-4C84-986C-04D797C39952}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E4C9D52E-2230-4C84-986C-04D797C39952}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E4C9D52E-2230-4C84-986C-04D797C39952}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1DA1A423-6971-41B5-8611-529CE6D6E64A}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace EntityFrameworkInFrontend.DAL;
2+
3+
public class Account
4+
{
5+
public Guid Id { get; set; }
6+
public string Username { get; set; } = "";
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace EntityFrameworkInFrontend.DAL;
4+
5+
public class BlazorSchoolContext : DbContext
6+
{
7+
public DbSet<Account> Accounts { get; set; }
8+
9+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseInMemoryDatabase("BlazorSchoolDB");
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@inherits LayoutComponentBase
2+
3+
@Body
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/"
2+
@using EntityFrameworkInFrontend.DAL
3+
@using Microsoft.EntityFrameworkCore
4+
@inject IDbContextFactory<BlazorSchoolContext> DbContextFactory
5+
6+
<PageTitle>Home</PageTitle>
7+
8+
<h1>Hello, world!</h1>
9+
10+
Welcome to your new app.
11+
12+
@if(AccountCounts == -1)
13+
{
14+
<p>Click Count User</p>
15+
}
16+
else
17+
{
18+
<p>Number of users: @AccountCounts</p>
19+
}
20+
21+
<button @onclick="AddUser" type="button">Add User</button>
22+
<button @onclick="CountUser" type="button">Count User</button>
23+
24+
@code {
25+
public int AccountCounts { get; set; } = -1;
26+
27+
public void AddUser()
28+
{
29+
var random = new Random();
30+
var context = DbContextFactory.CreateDbContext();
31+
32+
context.Accounts.Add(new()
33+
{
34+
Id = Guid.NewGuid(),
35+
Username = $"Blazor School {random.Next(0, 9999999)}"
36+
});
37+
38+
context.SaveChanges();
39+
}
40+
41+
public void CountUser()
42+
{
43+
var context = DbContextFactory.CreateDbContext();
44+
AccountCounts = context.Accounts.Count();
45+
}
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using EntityFrameworkInFrontend;
2+
using EntityFrameworkInFrontend.DAL;
3+
using Microsoft.AspNetCore.Components.Web;
4+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
5+
6+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
7+
builder.RootComponents.Add<App>("#app");
8+
builder.RootComponents.Add<HeadOutlet>("head::after");
9+
10+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
11+
builder.Services.AddDbContextFactory<BlazorSchoolContext>();
12+
13+
await builder.Build().RunAsync();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:36833",
8+
"sslPort": 0
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17+
"applicationUrl": "http://localhost:5086",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using Microsoft.AspNetCore.Components.Web.Virtualization
7+
@using Microsoft.AspNetCore.Components.WebAssembly.Http
8+
@using Microsoft.JSInterop
9+
@using EntityFrameworkInFrontend
10+
@using EntityFrameworkInFrontend.Layout

0 commit comments

Comments
 (0)