CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit
11.0.0-preview.3
Prefix Reserved
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
<PackageReference Include="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" Version="11.0.0-preview.3" />
<PackageVersion Include="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" Version="11.0.0-preview.3" />
<PackageReference Include="CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit" />
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"
#:package CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit@11.0.0-preview.3
#addin nuget:?package=CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit&version=11.0.0-preview.3&prerelease
#tool nuget:?package=CodoMetis.ValueRanges.EFCore.PostgreSQL.SchemaKit&version=11.0.0-preview.3&prerelease
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
Overlapsis SchemaKit'sWithUncheckedOperator(…, "&&")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,Float64RangeorFloat32Rangecolumn needsHasPostgresRangeandEnableUnmappedTypes, as in the EF Core guide.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- CodoMetis.EFCore.SchemaKit.PostgreSQL (= 11.0.0-preview.4)
- CodoMetis.ValueRanges.EFCore.PostgreSQL (>= 11.0.0-preview.3)
- CodoMetis.ValueRanges.NodaTime (>= 11.0.0-preview.3)
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