Skip to content

Commit 0dea7df

Browse files
committed
defining EF contexts
1 parent faa90a7 commit 0dea7df

8 files changed

+135
-1
lines changed

src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/CqrsSqlServer.Backend.csproj

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@
1616
<PackageReference Include="Petabridge.Cmd.Cluster" Version="$(PbmVersion)"/>
1717
<PackageReference Include="Petabridge.Cmd.Cluster.Sharding" Version="$(PbmVersion)"/>
1818
<PackageReference Include="Petabridge.Cmd.Host" Version="$(PbmVersion)"/>
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsVersion)" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsVersion)" />
1921
</ItemGroup>
2022

2123
<ItemGroup>
22-
<Folder Include="Actors\" />
24+
<Content Include="appsettings.json">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26+
</Content>
27+
<Content Include="appsettings.Development.json">
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
</Content>
30+
<Content Include="appsettings.Production.json">
31+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
32+
</Content>
33+
<None Remove="sharding.conf" />
2334
</ItemGroup>
2435

36+
<ItemGroup>
37+
<Folder Include="Configuration\" />
38+
</ItemGroup>
2539
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
},
9+
"ConnectionStrings": {
10+
"AkkaSqlConnection": "Server=localhost,1533; Database=Akka; User Id=sa; Password=yourStrong(!)Password; TrustServerCertificate=true;"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
15+
</ItemGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using CqrsSqlServer.DataModel.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace CqrsSqlServer.DataModel;
5+
6+
public class CqrsSqlServerContext : DbContext
7+
{
8+
public DbSet<ProductListing> Products { get; set; }
9+
10+
public const int ProductIdMaxLength = 128;
11+
public const int ProductNameMaxLength = 256;
12+
13+
public CqrsSqlServerContext(DbContextOptions<CqrsSqlServerContext> options)
14+
: base(options)
15+
{
16+
}
17+
18+
// The following configures EF to create a Sqlite database file in the
19+
// special "local" folder for your platform.
20+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
21+
{
22+
optionsBuilder.EnableDetailedErrors();
23+
base.OnConfiguring(optionsBuilder);
24+
}
25+
26+
protected override void OnModelCreating(ModelBuilder modelBuilder)
27+
{
28+
modelBuilder.Entity<ProductListing>(entity =>
29+
{
30+
entity.Property(c => c.ProductId)
31+
.HasMaxLength(ProductIdMaxLength)
32+
.IsRequired();
33+
34+
entity.Property(c => c.ProductName)
35+
.HasMaxLength(ProductNameMaxLength)
36+
.IsRequired();
37+
38+
entity.HasKey(c => c.ProductId);
39+
});
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ProductListing.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
namespace CqrsSqlServer.DataModel.Entities;
8+
9+
public class ProductListing
10+
{
11+
public string ProductId { get; set; } = null!;
12+
13+
public string ProductName { get; set; } = null!;
14+
15+
public decimal Price { get; set; }
16+
17+
public int RemainingInventory { get; set; }
18+
19+
public int SoldUnits { get; set; }
20+
21+
public decimal TotalRevenue { get; set; }
22+
23+
public DateTime Created { get; set; }
24+
25+
public DateTime LastModified { get; set; }
26+
}

src/cqrs/cqrs-sqlserver/CqrsSqlServer.sln

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.Shared", "Cqr
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.Backend", "CqrsSqlServer.Backend\CqrsSqlServer.Backend.csproj", "{E5872C18-242A-4F52-BBE4-CF4CB272CC4E}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqrsSqlServer.DataModel", "CqrsSqlServer.DataModel\CqrsSqlServer.DataModel.csproj", "{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -24,5 +26,9 @@ Global
2426
{E5872C18-242A-4F52-BBE4-CF4CB272CC4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2527
{E5872C18-242A-4F52-BBE4-CF4CB272CC4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2628
{E5872C18-242A-4F52-BBE4-CF4CB272CC4E}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{A1B9790C-AC65-46C0-8BC5-2C4013F5245D}.Release|Any CPU.Build.0 = Release|Any CPU
2733
EndGlobalSection
2834
EndGlobal

0 commit comments

Comments
 (0)