IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Entity Framework Core, DB first | Repository pattern | |
🗄️ Entity Framework Core - Model First (via Code First + Migrations) |
In classic EF6, Model First meant designing a model diagram (EDMX) and generating both the database and classes from it. In EF Core, there is no EDMX designer, but you can achieve a similar workflow by defining your domain model classes first and then generating the database schema using migrations.
// Install-Package Microsoft.EntityFrameworkCore
// Install-Package Microsoft.EntityFrameworkCore.SqlServer
// Install-Package Microsoft.EntityFrameworkCore.Tools
using Microsoft.EntityFrameworkCore;
// Step 1: Define Model
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
// Step 2: Define DbContext
public class SchoolContext : DbContext
{
public DbSet<Student> Students { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=.;Database=SchoolDb;Trusted_Connection=True;");
}
}
// Step 3: Apply Migrations
// From Package Manager Console:
// Add-Migration InitialCreate
// Update-Database
EF Core does not have a true Model First designer like EF6, but you can achieve the same effect by defining your model classes first and generating the database schema with migrations. This approach is widely used in modern .NET Core applications.
| Entity Framework Core, DB first | Repository pattern | |