- Home
- .NET code examples
- EF Core temporal tables in an ASP.NET Core Web API
EF Core temporal tables in an ASP.NET Core Web API
Use this Entity Framework Core temporal table to store, configure and query historic data.
You can read more about temporal tables in EF Core, or watch the video:
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
Software
This is the software that will need to be installed onto your machine.
Visual Studio 2026. Version 18.0.0 or above. It will work with the free community version.
.NET 10 SDK. Version 10.0.0 or above.
Import the database
This application integrates with a SQL Server database. Inside the Database folder, there is RoundTheCode_EFCoreTemporal.bacpac and RoundTheCode_EFCoreTemporal.bak. Use either of these database backups to import the database to your local SQL Server database server.
The application
Inside src/Api/appsettings.Development.json, find ConnectionStrings.EFCoreTemporalDbContextand point the connection string to your imported database.
Open up RoundTheCode.EFCoreTemporal.slnx, and run the application. The Swagger documentation will load at https://localhost:7131/swagger with these endpoints:
/api/products/{id}/as-of (GET)- Gets a product record at a particular moment in time. Try it with/api/products/1/as-of?utcDate=2026-06-12T12:47:00/api/products/{id}/all (GET)- Gets the history audit for a product record. Try it with/api/products/1/all/api/products/{id}/from-to (GET)- Gets the history audit for a product record between two dates. Records that became active at the end of thetoDateare included. Try it with/api/products/1/from-to?fromDate=2026-06-12T12:47:00&toDate=2026-06-12T12:48:00/api/products/{id}/between (GET)- Gets the history audit for a product record between two dates. Records that became active at the end of thetoDateare excluded. Try it with/api/products/1/between?fromDate=2026-06-12T12:47:00&toDate=2026-06-12T12:48:00/api/products/{id}/contained-in (GET)- Gets the history audit for a product record between two dates where the start date and end date occurred during the date range. Try it with/api/products/1/contained-in?fromDate=2026-06-12T12:00:00&toDate=2026-06-12T14:00:00/api/products (POST)- Inserts a product into the database. Try it with:{ "name": "Bracelet", "price": 150 }
/api/products/{id} (PUT)- Updates a product in the database. Try it with an{id}of1and this request body:{ "name": "Watch", "price": 50 }
/api/products/{id} (DELETE)- Deletes a product from the database. Try it with an{id}of1.
Related code examples