EfCoreTemporalTable 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package EfCoreTemporalTable --version 1.0.2
NuGet\Install-Package EfCoreTemporalTable -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EfCoreTemporalTable" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EfCoreTemporalTable --version 1.0.2
#r "nuget: EfCoreTemporalTable, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EfCoreTemporalTable as a Cake Addin
#addin nuget:?package=EfCoreTemporalTable&version=1.0.2

// Install EfCoreTemporalTable as a Cake Tool
#tool nuget:?package=EfCoreTemporalTable&version=1.0.2

Easily perform temporal queries on your favourite database by using Entity Framework Core

latest version

What is does?

There is no way querying temporal tables with Entity Framework Core except writing boring SQL code and executing raw queries. This package allows you to easily query your historic data and mix it with Entity Framework Core in an intuitive way.

All temporal criterias are supported and it works with all databases supported by EF Core and all operating systems supported by .NET Core (Windows/MacOS/Linux).

Installation

There are two ways to install the package:

  • via Visual Studio : Right Click on project > Manage NuGet packages > Search for "EfCoreTemporalTable" > Install
  • via command line: dotnet add package EfCoreTemporalTable

Usage

You can use it with your existing EF Core DbContext/DbSet. On top of your file, add using EfCoreTemporalTable;

On your DbSet properties you now get the following extension methods:

  • AsTemporalAll()
  • AsTemporalAsOf(date)
  • AsTemporalFrom(startDate, endDate)
  • AsTemporalBetween(startDate, endDate)
  • AsTemporalContained(startDate, endDate)

Those methods return an IQueryable<T>, meaning the execution is deferred and you can mix it with your usual EF Core and cutom methods.

For example, if you want to get all employees named "Lautrou" at the time of yesterday, and their company at that time but with up-to-date information:

var result = myDbContext.Employees
    .AsTemporalOf(DateTime.UtcNow.AddDays(-1))
    .Include(i=> i.Company)
    .FirstOrDefault(i => i.Name == "Lautrou");
    

The generated SQL query will be:

exec sp_executesql N'SELECT TOP(1) [e].[Id], [e].[CompanyId], [e].[Lastname], [e].[Firstname], [c].[Id], [c].[Name]
FROM (
    SELECT * FROM [dbo].[Employee] FOR SYSTEM_TIME AS OF @p0
) AS [e]
INNER JOIN [Company] AS [c] ON [e].[CompanyId] = [c].[Id]
WHERE [e].[Lastname] = N''Lautrou''',N'@p0 datetime2(7)',@p0='2019-11-27 17:26:10.1256588'

As you can see the SQL query is clean and the temporal parameter is a DbParameter (and not inlined).

You can of course join temporal tables, and write your C# in the way you want:

var employees = from employee in db.Employees.AsTemporalOf(date)
                join company in db.Entreprise.AsTemporalOf(date) on employee.CompanyId equals company.Id
                select new
                {
                    Employee = employee,
                    Company = company
                };
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 12,196 11/20/2021
1.0.4 28,085 1/13/2021
1.0.3 100,259 12/6/2019
1.0.2 471 12/5/2019
1.0.1 491 12/5/2019
1.0.0 557 12/5/2019