EFCore.ComplexIndexes.SqlServer
5.4.0
dotnet add package EFCore.ComplexIndexes.SqlServer --version 5.4.0
NuGet\Install-Package EFCore.ComplexIndexes.SqlServer -Version 5.4.0
<PackageReference Include="EFCore.ComplexIndexes.SqlServer" Version="5.4.0" />
<PackageVersion Include="EFCore.ComplexIndexes.SqlServer" Version="5.4.0" />
<PackageReference Include="EFCore.ComplexIndexes.SqlServer" />
paket add EFCore.ComplexIndexes.SqlServer --version 5.4.0
#r "nuget: EFCore.ComplexIndexes.SqlServer, 5.4.0"
#:package EFCore.ComplexIndexes.SqlServer@5.4.0
#addin nuget:?package=EFCore.ComplexIndexes.SqlServer&version=5.4.0
#tool nuget:?package=EFCore.ComplexIndexes.SqlServer&version=5.4.0
EFCore.ComplexIndexes.SqlServer
SQL Server index options for EFCore.ComplexIndexes. The core package is included automatically.
Brings the SQL Server option set to complex-property indexes:
- Clustered / nonclustered control
- Covering indexes (
INCLUDE) - Online index builds (
ONLINE = ON) - Fill factor
- Sort in tempdb
- Data compression (
ROW/PAGE)
Setup
None for migrations. Every option flows as a native SQL Server annotation that the provider's own
migrations SQL generator renders — install the package, declare your indexes, and run
dotnet ef migrations add.
One optional call exists. Database.EnsureCreated(), GenerateCreateScript() and the
pending-model-changes check in Migrate() run the runtime differ, which the design-time wiring never
reaches; without a registration, EnsureCreated() creates the tables and silently none of the
indexes. Register the differ once so those see the complex indexes too:
options.UseSqlServer(connectionString).UseSqlServerComplexIndexes();
AddSqlServerComplexIndexes() is the equivalent for a custom internal service provider.
Usage
builder.ComplexProperty(x => x.Email, c =>
c.Property(x => x.Value).HasColumnName("email"));
builder.HasComplexIndex(x => x.Email.Value, ix => ix
.IsUnique()
.HasName("ux_person_email")
.IncludeProperties("Name") // property paths resolve to columns
.IsCreatedOnline() // ONLINE = ON
.HasFillFactor(80));
// CREATE UNIQUE INDEX [ux_person_email] ON [person] ([email])
// INCLUDE ([name]) WITH (FILLFACTOR = 80, ONLINE = ON);
Also available: IsClustered(), SortInTempDb(), and
UseDataCompression(DataCompressionType.Page).
Filtered indexes (filter:) and DbOrder.Desc need nothing from this package — both ride on EF
Core's native index operation.
A filter may name properties instead of columns: filter: "{DeletedAt} IS NULL" resolves to
[deleted_at] IS NULL at migrations add.
Deliberate rejections
Declarations SQL Server cannot express fail at dotnet ef migrations add with a targeted error
rather than producing DDL that cannot apply:
- Expression parts — SQL Server has no functional-index DDL. Model the expression as a persisted computed column and index that column instead.
DbOrder.NullsFirst/NullsLast— there is noNULLS FIRST/NULLS LASTin T-SQL.- Clustered index with
INCLUDEcolumns — included columns are a nonclustered-index feature; a clustered index already stores every column. - Clustered filtered index — filtered indexes must be nonclustered.
- A second clustered index on a table — including the usual case, where the primary key already
holds the clustered slot. SQL Server clusters the primary key unless you declare
HasKey(...).IsClustered(false), so that is normally what a clustered complex index collides with.
Documentation
- SQL Server — the full index-option reference and every deliberate rejection
- Full documentation
Changelog
This package's changelog, or the root changelog covering all three packages.
MIT licensed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- EFCore.ComplexIndexes (>= 5.4.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.0 && < 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.