Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions
0.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions --version 0.1.1
NuGet\Install-Package Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions -Version 0.1.1
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="Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions" Version="0.1.1" />
<PackageReference Include="Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions" />
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 Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions --version 0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions, 0.1.1"
#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 Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions@0.1.1
#: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=Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions&version=0.1.1
#tool nuget:?package=Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions&version=0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EntityFrameworkCore: PostgreSQL Useful Extensions
Features
- Case-insensitive string matching for PostgreSQL:
ILike,ILikeStartsWith,ILikeEndsWith,ILikeContainsextension methods for use in LINQ-to-Entities queries, translated to PostgreSQLILIKE.
- Case-insensitive equality:
EqualsLowerCaseextension method for comparing strings in a case-insensitive manner.
- Dynamic query composition:
OrWhereextension method for combining multiple predicates with OR logic in LINQ queries.
Setup
Install the NuGet package:
dotnet add package Techbrifut.EntityFrameworkCore.PostgreSQL.UsefulExtensions
Register the useful extensions in your DbContext configuration:
var optionsBuilder = new DbContextOptionsBuilder()
.UseNpgsql("ConnectionString")
.UseUsefulExtensions(); // <- Add here
Or, if using dependency injection:
services.AddDbContext<AppDbContext>(options => options
.UseNpgsql("ConnectionString")
.UseUsefulExtensions() // <- Add here
);
Usage
Case-insensitive string matching
// Find users whose full name matches pattern, case-insensitively
var users = await db.Users.AsNoTracking()
.Where(user => user.FullName.ILike("%john%"))
.ToListAsync();
StartsWith/EndsWith/Contains (case-insensitive)
var users = await db.Users.AsNoTracking()
.Where(user => user.FirstName.ILikeStartsWith("jo")) // matches names starting with literal "jo"
.ToListAsync();
var usersEnding = await db.Users.AsNoTracking()
.Where(user => user.FirstName.ILikeEndsWith("son")) // matches names ending with literal "son"
.ToListAsync();
var usersContaining = await db.Users.AsNoTracking()
.Where(user => user.FullName.ILikeContains("Smith")) // matches users whose full name contains literal "Smith"
.ToListAsync();
| Method | SQL Translation | Parameter Value |
|---|---|---|
| ILikeStartsWith(col, v) | col ILIKE @p ESCAPE '\' | escaped(v) + "%" |
| ILikeEndsWith(col, v) | col ILIKE @p ESCAPE '\' | "%" + escaped(v) |
| ILikeContains(col, v) | col ILIKE @p ESCAPE '\' | "%" + escaped(v) + "%" |
Escaping: backslash (\) is used as the escape character; existing \, %, _ are escaped.
Case-insensitive equality
var users = await db.Users.AsNoTracking()
.Where(user => user.FirstName.EqualsLowerCase("john"))
.ToListAsync();
Translates to lower(source) = lower(value), enabling case-insensitive equality in SQL.
Dynamic OR queries
var users = await db.Users.AsNoTracking()
.Where(user => user.FirstName.EqualsLowerCase("john"))
.OrWhere(user => user.FirstName.EqualsLowerCase("jane"))
.ToListAsync();
If the query has no Where, behaves like a regular Where with the provided predicate
Notes
- These extension methods are only supported in LINQ-to-Entities queries and will be translated to SQL.
- Do NOT use them in client-side code; they will throw
NotSupportedException. - Consider proper indexing (e.g., functional indexes on lower(column)) when using case-insensitive comparisons for performance.
- For ILIKE with leading wildcards (e.g., %value), regular B-Tree indexes won't be used. Consider trigram (pg_trgm) indexes for faster pattern searches.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.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.