EfCoreTemporalTable.EfCore2
1.0.0
See the version list below for details.
dotnet add package EfCoreTemporalTable.EfCore2 --version 1.0.0
NuGet\Install-Package EfCoreTemporalTable.EfCore2 -Version 1.0.0
<PackageReference Include="EfCoreTemporalTable.EfCore2" Version="1.0.0" />
paket add EfCoreTemporalTable.EfCore2 --version 1.0.0
#r "nuget: EfCoreTemporalTable.EfCore2, 1.0.0"
// Install EfCoreTemporalTable.EfCore2 as a Cake Addin #addin nuget:?package=EfCoreTemporalTable.EfCore2&version=1.0.0 // Install EfCoreTemporalTable.EfCore2 as a Cake Tool #tool nuget:?package=EfCoreTemporalTable.EfCore2&version=1.0.0
Easily perform temporal queries on your favourite database by using Entity Framework Core
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.EntityFrameworkCore (>= 2.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.