Skip to content

Repository files navigation

CmdScale.EntityFrameworkCore.TimescaleDB

Test WorkflowNuGet downloadscodecovGitHub release (latest by date)GitHub issuesGitHub license

CmdScale.EntityFrameworkCore.TimescaleDB (aka Eftdb) is an EntityFrameworkCore provider for TimescaleDB. It lets you interact with TimescaleDB in a type-safe way with rich IntelliSense support, so you don't have to write SQL in magic strings like you did with plain Npgsql - all without losing a single feature of Npgsql.

Tip

Learn more about Eftdb in the documentation

📦 Installation

For a typical project, install both packages:

dotnet add package CmdScale.EntityFrameworkCore.TimescaleDB
dotnet add package CmdScale.EntityFrameworkCore.TimescaleDB.Design
PackageDescription
CmdScale.EntityFrameworkCore.TimescaleDBRuntime support for EF Core + TimescaleDB
CmdScale.EntityFrameworkCore.TimescaleDB.DesignDesign-time support for EF Core tooling (dotnet ef migrations and scaffolding)

Tip

You do NOT have to install Npgsql.EntityFrameworkCore.PostgreSQL — it is referenced transitively via CmdScale.EntityFrameworkCore.TimescaleDB.

⏩ Quick Start

1. Enable TimescaleDB

Chain .UseTimescaleDb() after .UseNpgsql() when configuring your DbContext. This registers all components that make EF Core aware of TimescaleDB's features.

string?connectionString=builder.Configuration.GetConnectionString("Timescale");builder.Services.AddDbContext<TimescaleContext>(options =>options.UseNpgsql(connectionString).UseTimescaleDb());

2. Define a Hypertable

You can either use the Fluent API or Data Annotations.

Fluent API

publicclassWeatherData{publicGuidId{get;set;}publicDateTimeTime{get;set;}publicdoubleTemperature{get;set;}publicdoubleHumidity{get;set;}}publicclassWeatherDataConfiguration:IEntityTypeConfiguration<WeatherData>{publicvoidConfigure(EntityTypeBuilder<WeatherData>builder){builder.HasKey(x =>new{x.Id,x.Time});builder.IsHypertable(x =>x.Time).WithChunkTimeInterval("7 days");}}

Data Annotations

[Hypertable(nameof(Time),ChunkTimeInterval="7 days")][PrimaryKey(nameof(Id),nameof(Time))]publicclassWeatherData{publicGuidId{get;set;}publicDateTimeTime{get;set;}publicdoubleTemperature{get;set;}publicdoubleHumidity{get;set;}}

3. Create and Apply a Migration

With the Design package installed, you can generate the migration with the default dotnet ef tools, just like you're used to.

dotnet ef migrations add "AddWeatherData"
dotnet ef database update

🔖 Release strategy

Eftdb targets the latest .NET LTS release. Support follows a rolling two-version model:

Support LevelScope
Current LTSNew features and bug fixes
Previous LTSCritical bug fixes only

Example: When .NET 12 (LTS) releases, it becomes the development target. .NET 10 receives only critical fixes, and .NET 8 support ends.

This policy balances maintainability with ensuring the most widely-used .NET versions receive support.

Questions or Ideas?

If you have questions, ideas, or need help getting started, feel free to open an issue. We’re happy to help and discuss!

Thank you for contributing! 💜

About

Extension of Npgsql to add support for TimescaleDB.

Topics

Resources

Code of conduct

Contributing

Stars

69 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages