Skip to content

Commit 40f9e92

Browse files
authored
Add Blazor Server example with SQL-Server (#618)
* BlazorAppServer Example * . * Culture * .
1 parent 937193a commit 40f9e92

31 files changed

Lines changed: 1302 additions & 0 deletions

‎System.Linq.Dynamic.Core.sln‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Te
122122
EndProject
123123
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Tests.Net6", "test\System.Linq.Dynamic.Core.Tests.Net6\System.Linq.Dynamic.Core.Tests.Net6.csproj", "{EDAB46DA-7079-42D7-819D-1932C542872F}"
124124
EndProject
125+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAppServer", "src-blazor\BlazorAppServer\BlazorAppServer.csproj", "{B133DA55-339D-4600-AED3-46214AD9F08A}"
126+
EndProject
125127
Global
126128
GlobalSection(SolutionConfigurationPlatforms) = preSolution
127129
Debug|Any CPU = Debug|Any CPU
@@ -744,6 +746,22 @@ Global
744746
{EDAB46DA-7079-42D7-819D-1932C542872F}.Release|x64.Build.0 = Release|Any CPU
745747
{EDAB46DA-7079-42D7-819D-1932C542872F}.Release|x86.ActiveCfg = Release|Any CPU
746748
{EDAB46DA-7079-42D7-819D-1932C542872F}.Release|x86.Build.0 = Release|Any CPU
749+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
750+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|Any CPU.Build.0 = Debug|Any CPU
751+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|ARM.ActiveCfg = Debug|Any CPU
752+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|ARM.Build.0 = Debug|Any CPU
753+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|x64.ActiveCfg = Debug|Any CPU
754+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|x64.Build.0 = Debug|Any CPU
755+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|x86.ActiveCfg = Debug|Any CPU
756+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Debug|x86.Build.0 = Debug|Any CPU
757+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|Any CPU.ActiveCfg = Release|Any CPU
758+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|Any CPU.Build.0 = Release|Any CPU
759+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|ARM.ActiveCfg = Release|Any CPU
760+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|ARM.Build.0 = Release|Any CPU
761+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|x64.ActiveCfg = Release|Any CPU
762+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|x64.Build.0 = Release|Any CPU
763+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|x86.ActiveCfg = Release|Any CPU
764+
{B133DA55-339D-4600-AED3-46214AD9F08A}.Release|x86.Build.0 = Release|Any CPU
747765
EndGlobalSection
748766
GlobalSection(SolutionProperties) = preSolution
749767
HideSolutionNode = FALSE
@@ -787,6 +805,7 @@ Global
787805
{A42F1470-7801-4A19-BCA3-08AF24F3BFC5} = {25E69107-C89E-4807-AA31-C49423F0F1E3}
788806
{2AC8773A-FCDD-4613-8758-E45E5F10CA3A} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
789807
{EDAB46DA-7079-42D7-819D-1932C542872F} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
808+
{B133DA55-339D-4600-AED3-46214AD9F08A} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
790809
EndGlobalSection
791810
GlobalSection(ExtensibilityGlobals) = postSolution
792811
SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20}
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.7" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
19+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
20+
<PackageReference Include="Oqtane.Shared" Version="3.1.4" />
21+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
22+
<!--<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.19" />-->
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace BlazorAppServer.Data;
5+
6+
[Table("Contract")]
7+
public class Contract
8+
{
9+
[Key]
10+
public int UId { get; set; }
11+
12+
public DateTime? DateC { get; set; }
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace BlazorAppServer.Data;
4+
5+
public class EntityContext : DbContext
6+
{
7+
public virtual DbSet<Contract> Contracts { get; set; }
8+
9+
public EntityContext()
10+
{
11+
12+
}
13+
14+
public EntityContext(DbContextOptions<EntityContext> options)
15+
: base(options)
16+
{
17+
}
18+
19+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
20+
{
21+
if (!optionsBuilder.IsConfigured)
22+
{
23+
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Contracts;Integrated Security=True;Connect Timeout=30;TrustServerCertificate=True");
24+
}
25+
}
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@page "/"
2+
@using System.Linq.Dynamic.Core
3+
4+
Current Culture = @System.Globalization.CultureInfo.CurrentCulture
5+
6+
<hr />
7+
8+
<pre>contractList : All</pre>
9+
@foreach (var contract in ContractListAll)
10+
{
11+
<div>@contract.DateC.ToString()</div>
12+
}
13+
14+
<hr />
15+
16+
<pre>contractList : Where</pre>
17+
@foreach (var contract in ContractList)
18+
{
19+
<div>@contract.DateC.ToString()</div>
20+
}
21+
22+
@code {
23+
public List<Contract> ContractList = new();
24+
public List<Contract> ContractListAll = new();
25+
26+
protected override async Task OnInitializedAsync()
27+
{
28+
await LoadDataAsync();
29+
}
30+
31+
public async Task LoadDataAsync()
32+
{
33+
await using var context = new EntityContext();
34+
await context.Database.EnsureCreatedAsync();
35+
36+
ContractList = context.Contracts.Where("DateC <= DateTime(2021, 1, 1)").ToList();
37+
38+
ContractListAll = context.Contracts.ToList();
39+
}
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
@namespace BlazorAppServer.Pages ;
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = "_Layout";
6+
}
7+
8+
<component type="typeof(App)" render-mode="ServerPrerendered" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@namespace BlazorAppServer.Pages ;
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<base href="~/" />
11+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
12+
<link href="css/site.css" rel="stylesheet" />
13+
<link href="BlazorApp1.styles.css" rel="stylesheet" />
14+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
15+
</head>
16+
<body>
17+
@RenderBody()
18+
19+
<div id="blazor-error-ui">
20+
<environment include="Staging,Production">
21+
An error has occurred. This application may no longer respond until reloaded.
22+
</environment>
23+
<environment include="Development">
24+
An unhandled exception has occurred. See browser dev tools for details.
25+
</environment>
26+
<a href="" class="reload">Reload</a>
27+
<a class="dismiss">🗙</a>
28+
</div>
29+
30+
<script src="_framework/blazor.server.js"></script>
31+
</body>
32+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddRazorPages();
5+
builder.Services.AddServerSideBlazor();
6+
7+
builder.Services.AddLocalization();
8+
9+
var app = builder.Build();
10+
11+
// Configure the HTTP request pipeline.
12+
if (!app.Environment.IsDevelopment())
13+
{
14+
app.UseExceptionHandler("/Error");
15+
}
16+
17+
app.UseStaticFiles();
18+
19+
app.UseRouting();
20+
21+
app.MapBlazorHub();
22+
app.MapFallbackToPage("/_Host");
23+
24+
app.UseRequestLocalization("fr-FR");
25+
26+
app.Run();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:13709",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"BlazorApp1": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "http://localhost:5058",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)