EFCore.TimescaleDB.Extensions 1.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EFCore.TimescaleDB.Extensions --version 1.0.0.1                
NuGet\Install-Package EFCore.TimescaleDB.Extensions -Version 1.0.0.1                
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="EFCore.TimescaleDB.Extensions" Version="1.0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EFCore.TimescaleDB.Extensions --version 1.0.0.1                
#r "nuget: EFCore.TimescaleDB.Extensions, 1.0.0.1"                
#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 EFCore.TimescaleDB.Extensions as a Cake Addin
#addin nuget:?package=EFCore.TimescaleDB.Extensions&version=1.0.0.1

// Install EFCore.TimescaleDB.Extensions as a Cake Tool
#tool nuget:?package=EFCore.TimescaleDB.Extensions&version=1.0.0.1                

EFCore.TimescaleDB.Extensions

NOTE: Not affiliated in anyway with Timescale DB nor is this super well made, but works for most cases.

Installation (SQL Server)

  1. Add EFCore.TimescaleDB.Extensions reference to your project.
  2. Add the following attribute to your startup/data project:
[assembly: DesignTimeServicesReference("EFCore.TimescaleDB.Extensions.DesignTimeServices, EFCore.TimescaleDB.Extensions")]
  1. Use the .ConfigureTimescale() extension of the DbContextOptionsBuilder, e.g.:
var host = Host.CreateDefaultBuilder(args)
               .ConfigureServices(
                   services =>
                   {
                       services.AddDbContext<ApplicationDbContext>(
                           options =>
                               options.UseNpgsql("<connection-string>")
                                      .ConfigureTimescale());
                   }).Build();
  1. Use the IsHyperProperty(...) extension of the PropertyBuilder to select the entities which should be audited:

[Keyless]
public class Product 
{
    public string Name { get; set; }
    public DateTimeOffset Time { get; set; }
}

public class ApplicationDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    { }

    protected override void OnModelCreating(ModelBuilder modelBuilder) 
        => modelBuilder.Entity<Product>().Property(x => x.Time).IsHyperProperty(retentionInterval: "24 hours"); // Use optional retention interval
}
  1. OR: Add support for configuring via the HyperTable attribute/convention by using the AddHyperTableConfiguration() extension on ModelConfigurationBuilder
[Keyless]
[HyperTable(nameof(Time), "24 hours")] // Optional retention interval
public class Product 
{
    public string Name { get; set; }
    public DateTimeOffset Time { get; set; }
}

public class ApplicationDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    { }

    protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
        => configurationBuilder.AddHyperTableConfiguration();
}
  1. Create a migration and update the database.

  2. Due to the way HyperTables works, there will be no Down command generated. To use those, either rewrite the down method. In the retention case I have added the command required as comment which can be used, but needs the table to still exist.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
2.0.0.1 116 11/22/2024
1.0.0.3 184 9/18/2024
1.0.0.2 114 9/18/2024
1.0.0.1 134 9/16/2024