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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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)
- Add
EFCore.TimescaleDB.Extensions
reference to your project. - Add the following attribute to your startup/data project:
[assembly: DesignTimeServicesReference("EFCore.TimescaleDB.Extensions.DesignTimeServices, EFCore.TimescaleDB.Extensions")]
- Use the
.ConfigureTimescale()
extension of theDbContextOptionsBuilder
, e.g.:
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(
services =>
{
services.AddDbContext<ApplicationDbContext>(
options =>
options.UseNpgsql("<connection-string>")
.ConfigureTimescale());
}).Build();
- Use the
IsHyperTable(...)
extension of theEntityTypeBuilder
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
}
- OR: Add support for configuring via the HyperTable attribute/convention by using the
AddHyperTableConfiguration()
extension onModelConfigurationBuilder
[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();
}
Create a migration and update the database.
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 | Versions 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.
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.