Overview
This sample demonstrates how to build a RESTful Web API using ASP.NET Core with Entity Framework Core for data access. It covers CRUD operations, async programming, and best practices for structuring a clean architecture.
Features
- ASP.NET Core 8.0 Web API
- EF Core 8.0 with SQLite provider
- Async/await for all database calls
- Repository & Unit of Work patterns
- Automapper for DTO mapping
- Integrated Swagger UI
Getting Started
Install
Run
API Docs
git clone https://github.com/microsoft-samples/webapi-efcore-sample.git
cd webapi-efcore-sample
dotnet restore
dotnet build
Code Sample
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>()
.HasKey(p => p.Id);
}
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}