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" />
                    
Directory.Packages.props
<PackageReference Include="Masterly.FluentRegex.EntityFrameworkCore" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Masterly.FluentRegex.EntityFrameworkCore&version=3.2.0
                    
Install as a Cake Tool

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 / ToMatchingListAsync run on every database: the SQL part is a proven superset of the pattern (the exact dialect regex, otherwise a superset LIKE plus a length bound, otherwise only a NULL check) and the .NET engine applies the exact pattern. Must rules of a ConstrainedPattern run 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 Server LIKEs compare under COLLATE Latin1_General_100_BIN2, where they mean exactly what .NET means: ^[A-Z]{3}-[0-9]{4}\z becomes the exact LIKE '[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9]' on any column. Declare UseLikeCollation(LikeCollation.Binary) for _BIN2/_BIN columns to drop the COLLATE and 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 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.

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
3.2.0 91 11/4/2026
3.1.1 90 11/3/2026
3.1.0 87 11/3/2026