### Configure DbContext with Custom Internal Service Provider Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Use this alternative setup when building your own `IServiceProvider` to enable expression indexes for PostgreSQL. It registers the necessary generator directly on the `IServiceCollection`. ```csharp var provider = new ServiceCollection() .AddEntityFrameworkNpgsql() .AddNpgsqlComplexIndexes() // ← Add this for expression indexes .BuildServiceProvider(); ``` -------------------------------- ### EF Core Temporal Constraint with Composite Key Columns Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Configure a temporal UNIQUE constraint with multiple key columns and a period column using this C# example. ```csharp builder.HasTemporalConstraint( keyColumns: b => new { b.Facility, b.RoomId }, period: b => b.ValidPeriod); // UNIQUE ("Facility", "RoomId", "ValidPeriod" WITHOUT OVERLAPS) ``` -------------------------------- ### SQL Example for Temporal UNIQUE Constraint Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md This SQL statement demonstrates how to add a temporal UNIQUE constraint to a table, ensuring that for a given room_id, the associated periods do not overlap. ```sql ALTER TABLE bookings ADD CONSTRAINT ak_bookings_room_period UNIQUE (room_id, period WITHOUT OVERLAPS); ``` -------------------------------- ### PostgreSQL expression index on a single expression Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Creates a PostgreSQL expression index on a single SQL expression. Requires `UseNpgsqlComplexIndexes()` setup. ```csharp // CREATE INDEX "IX_person_lowerlastname" ON person ((lower(last_name))); builder.HasExpressionIndex("lower(last_name)"); ``` -------------------------------- ### EF Core Migration Error for Invalid Period Type Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md This example illustrates the InvalidOperationException thrown during migration generation if the period property is not mapped to a PostgreSQL range type or a compatible NpgsqlRange CLR type. ```text The temporal constraint period property 'Start' on entity 'Booking' does not appear to be a range or multirange type. Found CLR type 'DateTime' (store type: 'timestamp with time zone'). Expected NpgsqlRange, a PostgreSQL range/multirange column type, or a store type ending in 'range' (e.g., daterange, int4multirange). ``` -------------------------------- ### Build Project Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Use this command to build the solution. It's also responsible for packing NuGet packages. ```bash dotnet build EFCore.ComplexIndexes.slnx ``` -------------------------------- ### Test Project Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Execute all tests in the project. Tests run in parallel at the method level. ```bash dotnet test EFCore.ComplexIndexes.Tests/EFCore.ComplexIndexes.Tests.csproj ``` -------------------------------- ### Pack NuGet Packages Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Manually pack NuGet packages for the library. This is also automatically triggered on build. ```bash dotnet pack EFCore.ComplexIndexes/EFCore.ComplexIndexes.csproj ``` -------------------------------- ### Expression Index Entry Point (PostgreSQL) Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md The entry point for expression indexes on PostgreSQL is the HasExpressionIndex method, which lives in the PostgreSQL-specific satellite assembly. ```csharp using EFCore.ComplexIndexes.PostgreSQL; // ... modelBuilder.Entity().HasExpressionIndex(x => x.SomeProperty.ToUpper()); ``` -------------------------------- ### PostgreSQL expression index with multiple ordered parts and name Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Configures a PostgreSQL expression index with multiple parts, including raw columns and SQL expressions, with explicit ordering and naming. Supports provider-specific options via a builder callback. ```csharp builder.HasExpressionIndex(idx => idx .Expression("country") // a plain column, written as raw SQL .Expression("lower(email)") // a SQL expression .IsUnique() .HasFilter("deleted_at IS NULL") .HasName("ix_person_country_email_ci")); // CREATE UNIQUE INDEX "ix_person_country_email_ci" // ON person ((country), (lower(email))) // WHERE deleted_at IS NULL; ``` -------------------------------- ### PostgreSQL GIN expression index for full-text search Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Creates a PostgreSQL GIN index on a full-text search expression. The expression is provided as a raw SQL string. ```csharp builder.HasExpressionIndex(idx => idx .Expression("to_tsvector('english', body)") .UseGin()); // CREATE INDEX ... ON articles USING gin ((to_tsvector('english', body))); ``` -------------------------------- ### Per-Column Sort Direction (Ascending) Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Demonstrates how to specify ascending sort direction for a column in a composite index. This is provider-agnostic and handled by the differ. ```csharp using EFCore.ComplexIndexes.Shared; // ... modelBuilder.Entity().HasComplexCompositeIndex(x => new { x.Name, DbOrder.Asc(x.City) }); ``` -------------------------------- ### Configure Temporal Constraint for Principal Entity Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Sets up a temporal constraint on the principal entity (e.g., Subscription). PostgreSQL requires a temporal UNIQUE/PRIMARY KEY constraint with WITHOUT OVERLAPS on the referenced columns. ```csharp modelBuilder.Entity(b => { // Principal side: PostgreSQL requires the referenced columns to have // a temporal UNIQUE/PRIMARY KEY constraint with WITHOUT OVERLAPS. b.HasTemporalConstraint( keyColumns: x => x.SubscriptionId, period: x => x.ValidDuring); }); ``` -------------------------------- ### PostgreSQL expression index with quoted identifiers Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Demonstrates how to correctly quote identifiers within PostgreSQL expression indexes using C# raw string literals to handle special characters or casing. ```csharp // CREATE INDEX ... ON "People" ((lower("Email"))); builder.HasExpressionIndex(""" lower("Email") """.Trim()); ``` -------------------------------- ### PostgreSQL covering expression index with INCLUDE Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Defines a unique PostgreSQL expression index that includes additional properties for covering index performance. Properties are specified as raw strings. ```csharp builder.HasExpressionIndex(idx => idx .Expression("lower(email)") .IsUnique() .IncludeProperties("display_name")); ``` -------------------------------- ### Per-Column Sort Direction (Descending) Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Shows how to specify descending sort direction for a column in a composite index. Note the explicit naming in the anonymous type. ```csharp using EFCore.ComplexIndexes.Shared; // ... modelBuilder.Entity().HasComplexCompositeIndex(x => new { x.Name, B = DbOrder.Desc(x.City) }); ``` -------------------------------- ### Generated SQL for Temporal Foreign Key Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Illustrates the SQL generated by EF Core for creating a temporal foreign key constraint in PostgreSQL. ```sql ALTER TABLE subscription_addons ADD CONSTRAINT fk_addons_subscriptions_temporal FOREIGN KEY (subscription_id, PERIOD active_during) REFERENCES subscriptions (subscription_id, PERIOD valid_during); ``` -------------------------------- ### EF Core Explicitly Declare btree_gist Extension Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Use this C# code to explicitly declare the btree_gist PostgreSQL extension for temporal constraints, allowing Npgsql's differ to manage it. ```csharp modelBuilder.UseBtreeGist(); ``` -------------------------------- ### Configure DbContext for PostgreSQL Expression Indexes Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Required for using `HasExpressionIndex(...)` with PostgreSQL. This call enables the custom migrations SQL generator needed to render expression indexes. ```csharp services.AddDbContext(options => options .UseNpgsql(connectionString) .UseNpgsqlComplexIndexes()); // ← required for HasExpressionIndex(...) ``` -------------------------------- ### PostgreSQL GIN index on a complex JSON property Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Configures a PostgreSQL-specific GIN index on a complex property, specifying the operator class for JSONB operations. ```csharp builder.ComplexProperty(x => x.Payload, c => c.Property(x => x.Json) .HasComplexIndex(idx => idx .UseGin() .HasOperators("jsonb_path_ops")) ); ``` -------------------------------- ### Define Temporal Foreign Key Relationship Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Establishes a temporal foreign key relationship between a dependent entity (e.g., SubscriptionAddOn) and a principal entity (e.g., Subscription). ```csharp modelBuilder.Entity(b => { b.HasTemporalForeignKey( dependentKeyColumns: x => x.SubscriptionId, dependentPeriod: x => x.ActiveDuring, principalKeyColumns: x => x.SubscriptionId, principalPeriod: x => x.ValidDuring, name: "fk_addons_subscriptions_temporal" ); }); ``` -------------------------------- ### EF Core Temporal Constraint with Single Key Column Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Use this C# code to configure a temporal UNIQUE constraint on a single key column and a period column using EF Core's HasTemporalConstraint API. ```csharp builder.HasTemporalConstraint( keyColumns: b => b.RoomId, period: b => b.ValidPeriod); // ALTER TABLE "Bookings" ADD CONSTRAINT "AK_Bookings__RoomId_ValidPeriod" // UNIQUE ("RoomId", "ValidPeriod" WITHOUT OVERLAPS); ``` -------------------------------- ### PostgreSQL expression index with unique and filter Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Defines a unique PostgreSQL expression index with a filter condition. The expression string is emitted verbatim. ```csharp builder.HasExpressionIndex( "lower(email)", isUnique: true, filter: "deleted_at IS NULL", indexName: "ix_person_email_ci"); ``` -------------------------------- ### Composite index with per-column sort direction Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Defines a composite index where specific columns can have their sort order (ascending or descending) explicitly set. This is rendered by all relational providers. ```csharp builder.HasComplexCompositeIndex( c => new { c.HybridDateTime.DateTime, Counter = DbOrder.Desc(c.HybridDateTime.Counter), c.Id }, indexName: "IX_Commits_DateTime_Counter_Id"); // CREATE INDEX "IX_Commits_DateTime_Counter_Id" ON ... ("DateTime", "Counter" DESC, "Id"); ``` -------------------------------- ### Run Single Test Method Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Filter tests to run only a specific method within a class. ```bash dotnet test --filter "FullyQualifiedName~MigrationModelDifferTests.SingleIndex_IsCreated" ``` -------------------------------- ### Composite index across scalar and nested properties Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Creates a unique composite index involving a scalar property and a nested property's value. ```csharp builder.HasComplexCompositeIndex( x => new { x.Name, x.EmailAddress.Value }, isUnique: true); ``` -------------------------------- ### Run Single Test Class Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/CLAUDE.md Filter tests to run only those within a specific class. ```bash dotnet test --filter "ClassName=MigrationModelDifferTests" ``` -------------------------------- ### EF Core Suppress Temporal Extension Auto-Injection Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md This C# snippet demonstrates how to suppress Npgsql's automatic injection of the btree_gist extension, useful if the extension is managed out-of-band. ```csharp modelBuilder.SuppressTemporalExtensionAutoInjection(); ``` -------------------------------- ### Single-column index on a complex property Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Defines a unique index on a specific property within a complex property. Supports filtering. ```csharp builder.ComplexProperty(x => x.EmailAddress, c => c.Property(x => x.Value) .HasComplexIndex(isUnique: true, filter: "deleted_at IS NULL") ); ``` -------------------------------- ### Define Temporal Foreign Key with Composite Keys Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md Configures a temporal foreign key relationship when both the dependent and principal entities use composite keys. ```csharp b.HasTemporalForeignKey( dependentKeyColumns: x => new { x.TenantId, x.SubscriptionId }, dependentPeriod: x => x.ActiveDuring, principalKeyColumns: x => new { x.TenantId, x.SubscriptionId }, principalPeriod: x => x.ValidDuring ); ``` -------------------------------- ### EF Core Temporal Constraint with Explicit Name Source: https://github.com/caffeinatedcoder/efcore.complexindexes/blob/main/README.md This C# snippet shows how to define a temporal UNIQUE constraint with a custom name for the constraint. ```csharp builder.HasTemporalConstraint( keyColumns: b => b.RoomId, period: b => b.ValidPeriod, name: "uk_room_no_overlap"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.