Compare commits

...

15 Commits

Author SHA1 Message Date
23a75282c1 Update README file. 2025-04-04 23:31:13 +02:00
25ede5cc28 Add logging to Entity Framework Core workload. 2025-04-04 20:12:03 +02:00
6e0167a051 Seed database with Teams. 2025-04-04 19:36:19 +02:00
451fb50cd8 Add comment to DbContext about where the database file is created. 2025-04-04 17:58:59 +02:00
5b3c661b67 Create initial migration.
deadballzone/EntityFrameworkCore.Console(master)$
dotnet ef migrations add InitialMigration --startup-project ./ --project ../EntityFrameworkCore.Data
2025-04-04 17:28:08 +02:00
de4c0d390c Update README. 2025-04-04 17:21:24 +02:00
a8b59a8ca2 Create DbContext file. 2025-04-04 17:21:16 +02:00
f58f92d0e0 Install Sqlite database provider for Entity Framework in Data project. 2025-04-04 17:20:57 +02:00
a53348294e Add reference to Data for the Console project. 2025-04-04 17:15:01 +02:00
a1b318e8bc Install Microsoft.EntityFrameworkCore.Design NuGet package 9.0.3 version in the Console project.
dotnet add package Microsoft.EntityFrameworkCore.Design --version 9.0.3
2025-04-04 17:12:49 +02:00
f1c4f4dda4 Add empty Console project to solution.
dotnet new console -n EntityFrameworkCore.Console
dotnet sln add EntityFrameworkCore.Console/EntityFrameworkCore.Console.csproj
2025-04-04 17:04:09 +02:00
601aff07c1 Add reference to Domain for the Data project.
Note that this command, did not work in Ubuntu. I just added the html to the project file myself.

dotnet reference add

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-reference-add
2025-04-04 16:25:46 +02:00
7bbe486bea Add Data and Domain projects to solution.
dotnet sln add EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj
dotnet sln add EntityFrameworkCore.Domain/EntityFrameworkCore.Domain.csproj
2025-04-04 16:09:04 +02:00
c8b1f5c391 Create a clean solution and move all files.
dotnet new sln -n deadballzone
2025-04-04 16:06:58 +02:00
3db3e262e1 Install Entity Framework Core NuGet package in Data project instead of solution.
dotnet remove package Microsoft.EntityFrameworkCore
cd EntityFrameworkCore.Data/
dotnet add package Microsoft.EntityFrameworkCore --version 9.0.3
2025-04-04 15:57:34 +02:00
18 changed files with 699 additions and 103 deletions

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View File

@ -1,6 +0,0 @@
namespace EntityFrameworkCore.Data;
public class Class1
{
}

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.Domain;
using Microsoft.Extensions.Logging;
namespace EntityFrameworkCore.Data;
public class DeadBallZoneLeagueDbContext : DbContext
{
private string DbPath;
public DeadBallZoneLeagueDbContext()
{
// In Ubuntu 24.04, the file is created here: /home/user/.local/share
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = Path.Combine(path, "DeadBallZoneLeague_EFCore.db");
}
public DbSet<Team> Teams { get; set; }
public DbSet<Coach> Coaches { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Data source={DbPath}")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging() // Do not allow this in Production.
.EnableDetailedErrors(); // Do not allow this in Production.
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Team>().HasData(
// Use hardcoded dates, not dynamic data such as new DateTimeOffset.UtcNow.DateTime for seeding.
new Team { TeamId = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)},
new Team { TeamId = 2, Name = "Voodoo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 3, Name = "Penal X", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 4, Name = "Neo Tokyo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 5, Name = "Neo Barcelona", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 6, Name = "Neo Manchester", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 7, Name = "Neo Bangkok", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 8, Name = "Neo Amsterdam", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 9, Name = "Killaklowns", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 10, Name = "Sol", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 11, Name = "DEC", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 12, Name = "Leopards", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 13, Name = "Harlequins", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 14, Name = "Gladiators", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
new Team { TeamId = 15, Name = "Fiz-O", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) }
);
}
}

View File

@ -6,4 +6,14 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../EntityFrameworkCore.Domain/EntityFrameworkCore.Domain.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,60 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
[Migration("20250404152141_InitialMigration")]
partial class InitialMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("TeamId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("TeamId");
b.ToTable("Teams");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,53 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Coaches",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
CreatedDate = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Coaches", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Teams",
columns: table => new
{
TeamId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: true),
CreatedDate = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teams", x => x.TeamId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Coaches");
migrationBuilder.DropTable(
name: "Teams");
}
}
}

View File

@ -0,0 +1,152 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
[Migration("20250404173338_SeededTeams")]
partial class SeededTeams
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("TeamId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("TeamId");
b.ToTable("Teams");
b.HasData(
new
{
TeamId = 1,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Delhi"
},
new
{
TeamId = 2,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Voodoo"
},
new
{
TeamId = 3,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Penal X"
},
new
{
TeamId = 4,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Tokyo"
},
new
{
TeamId = 5,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Barcelona"
},
new
{
TeamId = 6,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Manchester"
},
new
{
TeamId = 7,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Bangkok"
},
new
{
TeamId = 8,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Amsterdam"
},
new
{
TeamId = 9,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Killaklowns"
},
new
{
TeamId = 10,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Sol"
},
new
{
TeamId = 11,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "DEC"
},
new
{
TeamId = 12,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Leopards"
},
new
{
TeamId = 13,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Harlequins"
},
new
{
TeamId = 14,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Gladiators"
},
new
{
TeamId = 15,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Fiz-O"
});
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,118 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class SeededTeams : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Teams",
columns: new[] { "TeamId", "CreatedDate", "Name" },
values: new object[,]
{
{ 1, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Delhi" },
{ 2, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Voodoo" },
{ 3, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Penal X" },
{ 4, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Tokyo" },
{ 5, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Barcelona" },
{ 6, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Manchester" },
{ 7, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Bangkok" },
{ 8, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Neo Amsterdam" },
{ 9, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Killaklowns" },
{ 10, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Sol" },
{ 11, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "DEC" },
{ 12, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Leopards" },
{ 13, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Harlequins" },
{ 14, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Gladiators" },
{ 15, new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified), "Fiz-O" }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 1);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 2);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 3);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 4);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 5);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 6);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 7);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 8);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 9);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 10);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 11);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 12);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 13);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 14);
migrationBuilder.DeleteData(
table: "Teams",
keyColumn: "TeamId",
keyValue: 15);
}
}
}

View File

@ -0,0 +1,149 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
partial class DeadBallZoneLeagueDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("TeamId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("TeamId");
b.ToTable("Teams");
b.HasData(
new
{
TeamId = 1,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Delhi"
},
new
{
TeamId = 2,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Voodoo"
},
new
{
TeamId = 3,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Penal X"
},
new
{
TeamId = 4,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Tokyo"
},
new
{
TeamId = 5,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Barcelona"
},
new
{
TeamId = 6,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Manchester"
},
new
{
TeamId = 7,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Bangkok"
},
new
{
TeamId = 8,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Neo Amsterdam"
},
new
{
TeamId = 9,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Killaklowns"
},
new
{
TeamId = 10,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Sol"
},
new
{
TeamId = 11,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "DEC"
},
new
{
TeamId = 12,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Leopards"
},
new
{
TeamId = 13,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Harlequins"
},
new
{
TeamId = 14,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Gladiators"
},
new
{
TeamId = 15,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
Name = "Fiz-O"
});
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,6 +0,0 @@
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

View File

@ -1,23 +0,0 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5025",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7047;http://localhost:5025",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -25,6 +25,27 @@ adding to an existing solution:
`dotnet sln add Data/Data.csproj`
### Entity Framework commands
Create a migration, inside of the Console project, referring to the Data project:
`dotnet ef migrations add InitialMigration --startup-project ./ --project ../EntityFrameworkCore.Data`
Update the database:
`dotnet ef database update --startup-project ./ --project ../EntityFrameworkCore.Data`
Database-first scaffolding example: *(no need for escape slashes)*
`Scaffold-DbContext 'connection-string' Microsoft.EntityFrameworkCore.SqlServer -ContextDir ScaffoldDbContext -OutputDir ScallfoldModels`
`dotnet ef dbcontext scaffold "connection-string" Microsoft.EntityFrameworkCore.SqlServer --context-dir ScaffoldDbContext --output-dir ScaffoldModels --startup-project ./ --project ..\EntityFrameworkCore.Data\`
Using `-force` parameter to force overrides when scaffolding.
## Links
* [Entity Framework - Database providers](https://learn.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli)
## Terms
@ -32,3 +53,31 @@ A **database-context** is an abstraction of the database structure in code.
* It lists the models and their database table names.
* It instantiates a database connection during the runtime of the application.
* Allows configurations to be made in code.
The **migrations** provide a version-controlled method to maintain the state of the database.
* It is possible to track when, and by who changes were made.
* In the Up method, it is described which changes should be made.
* in the Down method, it is described which changes should be undone. This allows rollback.
* There is a history table that is kept by default to track migrations.
## Installed NuGet packages
A list of installed NuGet packages in this application.
Note that the [Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/9.0.3) is used for Powershell commands used in the Package Manager Console for Visual Studio and that [Microsoft.EntityFrameworkCore.Design](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Design/9.0.3) is used for cross-platform command tools.
### Console project
[Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/9.0.3)
* `dotnet add package Microsoft.EntityFrameworkCore.Tools --version 9.0.3`
### Data project
[Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/9.0.3)
* `dotnet add package Microsoft.EntityFrameworkCore --version 9.0.3`
[Microsoft.EntityFrameworkCore.Sqlite](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Sqlite/9.0.3)
* `dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 9.0.3`

View File

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

34
deadballzone.sln Normal file
View File

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Data", "EntityFrameworkCore.Data\EntityFrameworkCore.Data.csproj", "{7B006CF7-20E1-4E47-9D3A-3EC0D34E4FAD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Domain", "EntityFrameworkCore.Domain\EntityFrameworkCore.Domain.csproj", "{21C262BF-7D99-4EC1-AC21-3FF8230F902C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Console", "EntityFrameworkCore.Console\EntityFrameworkCore.Console.csproj", "{58F305A5-1C40-445D-8B2D-2CA4A0224274}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B006CF7-20E1-4E47-9D3A-3EC0D34E4FAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B006CF7-20E1-4E47-9D3A-3EC0D34E4FAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B006CF7-20E1-4E47-9D3A-3EC0D34E4FAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B006CF7-20E1-4E47-9D3A-3EC0D34E4FAD}.Release|Any CPU.Build.0 = Release|Any CPU
{21C262BF-7D99-4EC1-AC21-3FF8230F902C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21C262BF-7D99-4EC1-AC21-3FF8230F902C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21C262BF-7D99-4EC1-AC21-3FF8230F902C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21C262BF-7D99-4EC1-AC21-3FF8230F902C}.Release|Any CPU.Build.0 = Release|Any CPU
{58F305A5-1C40-445D-8B2D-2CA4A0224274}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58F305A5-1C40-445D-8B2D-2CA4A0224274}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58F305A5-1C40-445D-8B2D-2CA4A0224274}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58F305A5-1C40-445D-8B2D-2CA4A0224274}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -1,36 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "entity-framework", "entity-framework.csproj", "{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Data", "EntityFrameworkCore.Data\EntityFrameworkCore.Data.csproj", "{EB2B89D9-FE82-47CC-877F-223A4CA1755E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Domain", "EntityFrameworkCore.Domain\EntityFrameworkCore.Domain.csproj", "{DC955178-72C3-4574-86DE-1D966E38780E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.Build.0 = Release|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Release|Any CPU.Build.0 = Release|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55401B4B-4579-4281-B121-FCB05E8BD9C7}
EndGlobalSection
EndGlobal

View File

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>entity_framework</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
</ItemGroup>
</Project>