Created
October 10, 2023 10:10
-
-
Save admir-live/a86f4c63fbf79608f4f0a7c74ab27a4d to your computer and use it in GitHub Desktop.
Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.