Skip to content

Commit a54d491

Browse files
committed
added EF context
1 parent 0dea7df commit a54d491

6 files changed

+219
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
45
<TargetFramework>net8.0</TargetFramework>
56
<ImplicitUsings>enable</ImplicitUsings>
67
<Nullable>enable</Nullable>
78
</PropertyGroup>
89

910
<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" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsVersion)"/>
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3"/>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Remove="appsettings.json"/>
21+
<Content Include="appsettings.json">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</Content>
1524
</ItemGroup>
1625

1726
</Project>

src/cqrs/cqrs-sqlserver/CqrsSqlServer.DataModel/Migrations/20240325192428_InitialCreat.Designer.cs

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace CqrsSqlServer.DataModel.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class InitialCreat : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "Products",
16+
columns: table => new
17+
{
18+
ProductId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
19+
ProductName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
20+
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
21+
RemainingInventory = table.Column<int>(type: "int", nullable: false),
22+
SoldUnits = table.Column<int>(type: "int", nullable: false),
23+
TotalRevenue = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
24+
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
25+
LastModified = table.Column<DateTime>(type: "datetime2", nullable: false)
26+
},
27+
constraints: table =>
28+
{
29+
table.PrimaryKey("PK_Products", x => x.ProductId);
30+
});
31+
}
32+
33+
/// <inheritdoc />
34+
protected override void Down(MigrationBuilder migrationBuilder)
35+
{
36+
migrationBuilder.DropTable(
37+
name: "Products");
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// <auto-generated />
2+
using System;
3+
using CqrsSqlServer.DataModel;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Metadata;
7+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8+
9+
#nullable disable
10+
11+
namespace CqrsSqlServer.DataModel.Migrations
12+
{
13+
[DbContext(typeof(CqrsSqlServerContext))]
14+
partial class CqrsSqlServerContextModelSnapshot : ModelSnapshot
15+
{
16+
protected override void BuildModel(ModelBuilder modelBuilder)
17+
{
18+
#pragma warning disable 612, 618
19+
modelBuilder
20+
.HasAnnotation("ProductVersion", "8.0.3")
21+
.HasAnnotation("Relational:MaxIdentifierLength", 128);
22+
23+
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
24+
25+
modelBuilder.Entity("CqrsSqlServer.DataModel.Entities.ProductListing", b =>
26+
{
27+
b.Property<string>("ProductId")
28+
.HasMaxLength(128)
29+
.HasColumnType("nvarchar(128)");
30+
31+
b.Property<DateTime>("Created")
32+
.HasColumnType("datetime2");
33+
34+
b.Property<DateTime>("LastModified")
35+
.HasColumnType("datetime2");
36+
37+
b.Property<decimal>("Price")
38+
.HasColumnType("decimal(18,2)");
39+
40+
b.Property<string>("ProductName")
41+
.IsRequired()
42+
.HasMaxLength(256)
43+
.HasColumnType("nvarchar(256)");
44+
45+
b.Property<int>("RemainingInventory")
46+
.HasColumnType("int");
47+
48+
b.Property<int>("SoldUnits")
49+
.HasColumnType("int");
50+
51+
b.Property<decimal>("TotalRevenue")
52+
.HasColumnType("decimal(18,2)");
53+
54+
b.HasKey("ProductId");
55+
56+
b.ToTable("Products");
57+
});
58+
#pragma warning restore 612, 618
59+
}
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="Program.cs" company="Akka.NET Project">
3+
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using CqrsSqlServer.DataModel;
8+
using Microsoft.EntityFrameworkCore;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
13+
var hostBuilder = new HostBuilder()
14+
.ConfigureAppConfiguration((hostContext, configApp) =>
15+
{
16+
configApp.AddJsonFile("appsettings.json");
17+
})
18+
.ConfigureServices((hostContext, services) =>
19+
{
20+
services.AddDbContext<CqrsSqlServerContext>(options =>
21+
{
22+
// disable change tracking for all implementations of this context
23+
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
24+
options.UseSqlServer(hostContext.Configuration.GetConnectionString("AkkaSqlConnection"));
25+
});
26+
});
27+
28+
await hostBuilder.Build().RunAsync();
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+
}

0 commit comments

Comments
 (0)