EFCore.TimescaleDB.Extensions 2.0.0.1

dotnet add package EFCore.TimescaleDB.Extensions --version 2.0.0.1                
NuGet\Install-Package EFCore.TimescaleDB.Extensions -Version 2.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="2.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 2.0.0.1                
#r "nuget: EFCore.TimescaleDB.Extensions, 2.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=2.0.0.1

// Install EFCore.TimescaleDB.Extensions as a Cake Tool
#tool nuget:?package=EFCore.TimescaleDB.Extensions&version=2.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 IsHyperTable(...) extension of the EntityTypeBuilder to select the entities which should be configured:

[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>().IsHyperTable(nameof(Product.Time, retentionInterval: "24 hours", chunkSize: "1 day"); // Use optional intervals
}
  1. OR: Add support for configuring via the HyperTable attribute/convention by using the AddHyperTableConfiguration() extension on ModelConfigurationBuilder
[Keyless]
[HyperTable(nameof(Time), "24 hours", "1 day")] // Optional intervals
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 net9.0 is compatible. 
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