Skip to content

Instantly share code, notes, and snippets.

@atrakic
Forked from admir-live/Example.cs
Created December 2, 2025 20:50
Show Gist options
  • Select an option

  • Save atrakic/b8cd3225dd8a6f1548e7d90cca9dc921 to your computer and use it in GitHub Desktop.

Select an option

Save atrakic/b8cd3225dd8a6f1548e7d90cca9dc921 to your computer and use it in GitHub Desktop.
Example
1. Install or Update EF Core CLI
dotnet tool install --global dotnet-ef
2. Update Your DbContext
In your DbContext class, use the IsTemporal method to configure the entity as a temporal table.
using Microsoft.EntityFrameworkCore;
using System;
namespace YourNamespace
{
public class YourDbContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>()
.ToTable("Customers", b => b.IsTemporal());
modelBuilder.Entity<Product>()
.ToTable("Products", b => b.IsTemporal());
modelBuilder.Entity<Order>()
.ToTable("Orders", b => b.IsTemporal());
}
}
}
3. Create a Migration
dotnet ef migrations add AddTemporalTables
4. Update Database
dotnet ef database update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment