Aug 26, 2024
Program.cs
appsettings.json
(where database connections are stored)Student
:
ID
(Primary Key)FirstName
MiddleName
LastName
FullName
(combination of first, middle, and last names)Gender
(nullable)Context
and define a class named ApplicationDbContext
that derives from DbContext
.Npgsql.EntityFrameworkCore.PostgreSQL
).appsettings.json
, define the connection string for PostgreSQL:
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=University;Username=postgres;Password=yourpassword"
}
ApplicationDbContext
in Program.cs
:
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(connectionString));
University
using PostgreSQL interface.Student
table:
Add-Migration InitialMigration
Update-Database
Student
model: