Storing Data in a PostgreSQL Database

Starting a PostgreSQL Database in Docker https://www.postgresql.org docker pull postgres docker run --name postgres -e POSTGRES_PASSWORD=postgres -e TZ=Asia/Shanghai -d -p 5432:5432 postgres Connecting to the PostgreSQL Database with PgAdmin https://www.pgadmin.org SHOW timezone; Using the PostgreSQL Database with EF Core dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL Defining the Entity Type public class User { public int Id { get; set; } public string UserName { get; set; } public string PasswordHash { get; set; } public DateTimeOffset CreationTime { get; set; } = DateTimeOffset.UtcNow; } Configuring the Entity Type public class UserEntityTypeConfiguration : IEntityTypeConfiguration<User> { public void Configure(EntityTypeBuilder<User> builder) { builder.ToTable("Users"); builder.HasKey(x => x.Id); builder.Property(x => x.UserName).IsRequired().HasMaxLength(50); builder.Property(x => x.PasswordHash).IsRequired().HasMaxLength(50); builder.Property(x => x.CreationTime); } } Creating the DbContext public class IdentityServiceDbContext : DbContext { public IdentityServiceDbContext(DbContextOptions<IdentityServiceDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } } Database Connection String { "ConnectionStrings": { "IdentityDatabase": "Host=localhost;Port=5432;Database=IdentityService;Username=postgres;Password=postgres" } } Registering the DbContext builder.Services.AddDbContext<IdentityServiceDbContext>(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("IdentityDatabase")); }); Migrating the Database dotnet tool install --global dotnet-ef dotnet add package Microsoft.EntityFrameworkCore.Design dotnet ef migrations add InitialCreate --output-dir EntityFrameworks/Migrations dotnet ef database update PostgreSQL Database Naming Conventions https://github.com/efcore/EFCore.NamingConventions ...

March 10, 2026

Testing in the Zero Framework

Automated testing is an excellent way to make sure application code does what its author intends. The Zero Framework provides unit tests, integration tests, and load tests. Testing frameworks on the .NET platform include xUnit, NUnit, and MSTest, with xUnit being the most widely used. Whichever testing framework you use, tests can be run from the command line or from an IDE. Unit Tests A unit test is a test that exercises an individual software component or method, also known as the “unit of work.” Unit tests should only test code within the developer’s control; they do not test infrastructure concerns. Infrastructure concerns include interactions with databases, file systems, and network resources. Unit tests in the Zero Framework use the xUnit framework. ...

March 10, 2026

Updating from .NET 8.0 to .NET 9.0

Update Visual Studio to the Latest Preview Download and install the Visual Studio preview, and install the .NET 9.0 SDK. Update the Project File Open the project file and change <TargetFramework>net8.0</TargetFramework> to <TargetFramework>net9.0</TargetFramework>. Update NuGet Packages Open the NuGet package manager and update all NuGet packages to the latest version. Update the Aspire and MAUI Workloads Open the Aspire workload and update all Aspire packages to the latest version. dotnet workload install aspire android ios maccatalyst maui-android maui-desktop maui-mobile maui-windows To Add Tab Autocompletion to PowerShell for the .NET CLI https://learn.microsoft.com/zh-cn/dotnet/core/tools/enable-tab-autocomplete

March 10, 2026

Upgrading the Zero Framework to Aspire 13.0

Simplified Solution File Format From sln to slnx: the new slnx format is easier to read and maintain, removes redundant information, and makes the project structure clearer. dotnet sln migrate Also update the sln files referenced in slnf files to slnx files. Upgrading the Target Framework to .NET 10 In the project files, change the target framework from net9.0 to net10.0: <TargetFramework>net10.0</TargetFramework> Upgrading Aspire to 13.0.0 In the project files, update the Aspire package version to 13.0.0 ...

March 10, 2026

Upgrading the Zero Framework to Aspire 9.0

Upgrading the Visual Studio Development Tools Use Visual Studio Installer to upgrade. After upgrading to v17.12, the .NET 9.0 SDK and the Aspire 9.0 workload are installed automatically. Non-Visual Studio Development Environments Install .NET Core SDK 9.0 Install the latest .NET SDK 9.0 release Check the .NET SDK version: dotnet --version dotnet --list-sdks Upgrade the Aspire Workload Run the following commands in the project directory: dotnet workload uninstall aspire dotnet workload install aspire dotnet workload list dotnet workload update Upgrading the Project Files Add the new node to the Host project: ...

March 10, 2026

User Interfaces and Design Languages

User Experience User Experience (UX) refers to how users feel when using a product. It is a comprehensive concept that includes users’ perceptions, emotions, attitudes, and moods toward the product. User Experience Design (UXD) is a user-centered design methodology aimed at increasing user satisfaction and improving users’ understanding and use of the product. Factors such as color, typography, layout, and interaction all affect user experience. Therefore, user experience must be considered when designing user interfaces, providing a clean, intuitive, and easy-to-use interface to improve user satisfaction. ...

March 10, 2026

Using HybridCache hybrid caching library

Hybrid cache can use both memory cache and distributed cache, which can improve cache hit rate and reduce access to distributed cache, thereby improving performance. When getting data from the cache, it will first get the data from the memory cache, if there is no data in the memory cache, it will get the data from the distributed cache. When writing data to the cache, it writes data to both the in-memory cache and the distributed cache. Service 1 ----> HybridCache ----> MemoryCache ----> DistributedCache https://learn.microsoft.com/zh-cn/azure/architecture/best-practices/caching ...

March 10, 2026

Zero Framework upgraded to Aspire 9.3 version

Remove the IsAspireHost property from the Host project <IsAspireHost>true</IsAspireHost> Workload upgrade dotnet workload update Upgrade Visual Studio to the latest version Upgrade to the latest version via Visual Studio Installer. Items can be upgraded using AI GitHub Copilot App Modernization - Upgrade for .NET is a powerful Visual Studio extension that works with you to upgrade projects to newer versions of .NET, upgrade dependencies, and apply code fixes. GitHub Copilot application modernization is distributed as a Visual Studio extension and is an interactive upgrade process. ...

March 10, 2026

WebApp

March 10, 2026