CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit 11.0.0-preview.3

Prefix Reserved
This is a prerelease version of CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit.
dotnet add package CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit --version 11.0.0-preview.3
                    
NuGet\Install-Package CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit -Version 11.0.0-preview.3
                    
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="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" Version="11.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" Version="11.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit --version 11.0.0-preview.3
                    
#r "nuget: CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit, 11.0.0-preview.3"
                    
#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.
#:package CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit@11.0.0-preview.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit&version=11.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit&version=11.0.0-preview.3&prerelease
                    
Install as a Cake Tool

CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit

This package lets you write an exclusion constraint over a range column with a typed Overlaps. The constraint itself comes from CodoMetis.EFCore.SchemaKit.PostgreSQL, and the columns from the CodoMetis.ValueRanges EF Core package. SchemaKit's own Overlaps takes Npgsql's NpgsqlRange<T> only. This package adds one for every range and range set type of CodoMetis.ValueRanges and CodoMetis.ValueRanges.NodaTime.

dotnet add package CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit

Turn on both packages inside UseNpgsql:

options.UseNpgsql(connectionString, npgsql =>
{
    npgsql.UseValueRanges();   // or UseValueRangesNodaTime()
    npgsql.UseSchemaKit();
});

Then declare the constraint on the entity:

using CodoMetis.EFCore.SchemaKit.PostgreSQL;

modelBuilder.Entity<Booking>().DeclarePostgres(pg =>
[
    pg.Exclusion(
        pg.Equal(b => b.RoomId)       // same room …
          .Overlaps(b => b.Period),   // … must not overlap in time
        name: "ex_booking_room_period")
]);

The migration creates this:

ALTER TABLE "Bookings" ADD CONSTRAINT ex_booking_room_period
  EXCLUDE USING gist ("RoomId" WITH =, "Period" WITH &&);

A second booking for the same room whose Period overlaps an existing one is rejected with 23P01 (exclusion_violation). Adjacent periods are accepted.

What Overlaps takes

Overlaps compiles for a property of any of these types, or of their range set types (DateRangeSet, LocalDateRangeSet and so on, stored as multiranges):

Package Range types
CodoMetis.ValueRanges Int32Range, Int64Range, DecimalRange, DateRange, DateTimeRange, DateTimeOffsetRange, TimeRange, Float64Range, Float32Range
CodoMetis.ValueRanges.NodaTime LocalDateRange, LocalDateTimeRange, InstantRange, YearMonthRange

Any other property doesn't compile. That is the difference from WithUncheckedOperator(b => b.Period, "&&"), which takes any type and leaves the check to PostgreSQL when the migration runs.

You can write it in three places:

  • After Equal: pg.Equal(b => b.RoomId).Overlaps(b => b.Period) rejects an overlap in the same room.
  • First: pg.Overlaps(b => b.Period) rejects every overlap, whatever the other columns hold.
  • After another element: ….Overlaps(b => b.Period).Overlaps(b => b.Hours) rejects a row that overlaps in both.

Good to know

  • The package writes no SQL. Each Overlaps is SchemaKit's WithUncheckedOperator(…, "&&") with the type checked, so SchemaKit renders and creates the constraint.
  • It pins one SchemaKit preview. SchemaKit's previews change API and stored form between them, so this package names the version it was tested with exactly. Install that one.
  • It brings CodoMetis.ValueRanges.NodaTime with it, because the NodaTime range types are in the overload list.
  • A custom range type needs its type created. A TimeRange, Float64Range or Float32Range column needs HasPostgresRange and EnableUnmappedTypes, as in the EF Core guide.
Product Compatible and additional computed target framework versions.
.NET net11.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
11.0.0-preview.3 0 11/30/2026

The first release of this package. It ships as a preview while CodoMetis.EFCore.SchemaKit.PostgreSQL is one.

Added

- EF Core: Overlaps on SchemaKit's PgSchema<TEntity>, ExclusionDraft<TEntity> and ExclusionElements<TEntity> takes every range and range set type of CodoMetis.ValueRanges and CodoMetis.ValueRanges.NodaTime, so pg.Exclusion(pg.Equal(b => b.RoomId).Overlaps(b => b.Period)) compiles for a DateRange or a LocalDateRange and not for any other property (Reject overlapping rows (https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#reject-overlapping-rows-with-an-exclusion-constraint)).
- Packaging: references CodoMetis.EFCore.SchemaKit.PostgreSQL 11.0.0-preview.4 exactly, the version it was compiled and tested against (#540 (https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/540), #614 (https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/614)).

Full changelog: https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/v11.0.0-preview.3/src/CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit/CHANGELOG.md