Masterly.FluentRegex.EntityFrameworkCore
3.2.0
dotnet add package Masterly.FluentRegex.EntityFrameworkCore --version 3.2.0
NuGet\Install-Package Masterly.FluentRegex.EntityFrameworkCore -Version 3.2.0
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="Masterly.FluentRegex.EntityFrameworkCore" Version="3.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Masterly.FluentRegex.EntityFrameworkCore" Version="3.2.0" />
<PackageReference Include="Masterly.FluentRegex.EntityFrameworkCore" />
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 Masterly.FluentRegex.EntityFrameworkCore --version 3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Masterly.FluentRegex.EntityFrameworkCore, 3.2.0"
#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 Masterly.FluentRegex.EntityFrameworkCore@3.2.0
#: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=Masterly.FluentRegex.EntityFrameworkCore&version=3.2.0
#tool nuget:?package=Masterly.FluentRegex.EntityFrameworkCore&version=3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Masterly.FluentRegex.EntityFrameworkCore
Entity Framework Core integration for Masterly.FluentRegex: run fluent patterns inside LINQ queries, translated to the database's own regex dialect, with proven index-friendly prefilters and CHECK constraints generated from the same pattern.
using Masterly.FluentRegex;
using Masterly.FluentRegex.EntityFrameworkCore;
public static class Patterns
{
public static readonly Pattern Sku = Pattern.With
.StartOfLine.UppercaseLetter.Repeat.Times(3).Literal("-").AsciiDigit.Repeat.Times(4).EndOfLine;
}
services.AddDbContext<ShopContext>(options => options
.UseNpgsql(connectionString)
.UseFluentRegex()); // dialect detected from the provider
// WHERE p."Sku" IS NOT NULL AND p."Sku" ~ '\A[A-Z]{3}-[0-9]{4}(?=\n?\Z)' AND length(p."Sku") <= 9
// The regex keeps the exact .NET meaning ($ also accepts a final newline); the length bound is proven.
List<Product> skus = await db.Products.Where(p => Patterns.Sku.IsMatch(p.Sku!)).ToListAsync();
// Works on every database: SQL prefilter (a proven superset) + exact .NET match
List<Product> exact = await db.Products.ToMatchingListAsync(p => p.Sku, Patterns.Sku);
// CHECK ("Sku" ~ '...') on PostgreSQL, REGEXP_LIKE([Sku], N'...') on SQL Server 2025, ...
// Same semantics as Pattern.IsMatch and [MatchesPattern], so the database and the validator never disagree.
modelBuilder.Entity<Product>().Property(p => p.Sku).HasPattern(Patterns.Sku);
| Dialect | Detected from | IsMatch / Matches |
Group |
Replace |
CHECK constraint |
|---|---|---|---|---|---|
| PostgreSQL | Npgsql | col ~ 're' |
regexp_substr(col, re, 1, 1, '', n) |
regexp_replace(col, re, repl, 'g') |
yes |
| MySQL 8 | Pomelo, or Oracle's MySql.EntityFrameworkCore (EF Core 10) | REGEXP_LIKE(col, 're', 'c') |
no | REGEXP_REPLACE(col, re, repl) |
yes |
| MariaDB | Pomelo (server version) | col REGEXP 're' |
no | REGEXP_REPLACE(col, re, repl) |
yes |
| SQL Server 2025 / Azure SQL | compatibility level 170+ | IIF(REGEXP_LIKE(col, N're'), 1, 0) = 1 |
REGEXP_SUBSTR(col, re, 1, 1, 'c', n) |
REGEXP_REPLACE(col, re, repl) |
yes |
| SQL Server (older) | SQL Server provider | LIKE proven exact by language algebra, compared under BIN2, otherwise throws with guidance |
no | no | exact LIKE or throws |
| SQLite | Microsoft.Data.Sqlite | col REGEXP 're' (.NET engine) |
no | no | yes |
MatchingAsync/ToMatchingListAsyncrun on every database: the SQL part is a proven superset of the pattern (the exact dialect regex, otherwise a supersetLIKEplus a length bound, otherwise only a NULL check) and the .NET engine applies the exact pattern.Mustrules of aConstrainedPatternrun in .NET.- Index hints (on by default): proven facts such as a required prefix add
AND col LIKE 'prefix%'and an upper length bound next to the regex, so a B-tree index can narrow the scan without changing results. - NULL never matches, exactly as in .NET:
Matches(NULL)is false, so!Matches(...)keeps NULL rows, with or without index hints. - SQL Server's linguistic collations fold case, merge combining accents and skip ignorable characters in
LIKE, so SQL ServerLIKEs compare underCOLLATE Latin1_General_100_BIN2, where they mean exactly what .NET means:^[A-Z]{3}-[0-9]{4}\zbecomes the exactLIKE '[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9]'on any column. DeclareUseLikeCollation(LikeCollation.Binary)for_BIN2/_BINcolumns to drop theCOLLATEand keep index seeks. SqlRegex.Condition("\"Email\"", pattern, SqlDialect.PostgreSql)returns the predicate as raw SQL for Dapper.- Targets .NET 8 (EF Core 8) and .NET 10 (EF Core 10). Full documentation:
docs/features/entity-framework.md.
| 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Masterly.FluentRegex (>= 3.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.14)
-
net8.0
- Masterly.FluentRegex (>= 3.2.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.33)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.