Skip to content

Instantly share code, notes, and snippets.

@admir-live
Created October 10, 2023 10:10
Show Gist options
  • Select an option

  • Save admir-live/a86f4c63fbf79608f4f0a7c74ab27a4d to your computer and use it in GitHub Desktop.

Select an option

Save admir-live/a86f4c63fbf79608f4f0a7c74ab27a4d 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
@admir-live
Copy link
Author

After running these commands, your database should now have the configured temporal tables. The migration will handle adding the necessary columns and settings to enable temporal features on the tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment