Myth.Specification 3.0.4-preview.16

This is a prerelease version of Myth.Specification.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Myth.Specification --version 3.0.4-preview.16
                    
NuGet\Install-Package Myth.Specification -Version 3.0.4-preview.16
                    
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="Myth.Specification" Version="3.0.4-preview.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Myth.Specification" Version="3.0.4-preview.16" />
                    
Directory.Packages.props
<PackageReference Include="Myth.Specification" />
                    
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 Myth.Specification --version 3.0.4-preview.16
                    
#r "nuget: Myth.Specification, 3.0.4-preview.16"
                    
#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 Myth.Specification@3.0.4-preview.16
                    
#: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=Myth.Specification&version=3.0.4-preview.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Myth.Specification&version=3.0.4-preview.16&prerelease
                    
Install as a Cake Tool

Myth.Specification

NuGet Version NuGet Version

License

pt-br en

It is a .NET library for constructing queries in a very readable way, keeping the business rules in mind.

⭐ Features

  • Easy readability
  • Easy writing
  • Business rules ahead
  • Simplified use

🔮 Usage

To use, the following pattern must be followed:

var spec = SpecBuilder<Entity>
	.Create()
	.And(...)
	.Or(...)
	.Not()
  ...

The main idea is that every bit of your filter is built with the business rule in mind.

Suppose I have a Person table and I need to filter people with a female gender identity, who are from generation Z and who live in city X.

To do this, I should create a static class with the creation of each part of this filter, as follows:

public static class PersonSpecifications {
	public static ISpec<Person> IsGenerationX(this ISpec<Person> spec) {
		return spec.And(person => person.Birthdate.Year >= 2000);
	}

	public static ISpec<Person> IsIdentifiedAsFemale(this ISpec<Person> spec) {
		return spec.And(person => person.Gender == "female");
	}

	public static ISpec<Person> LivesOnCity(this ISpec<Person> spec, string city) {
		return spec.And(person => person.Address.City == city);
	}
}

And then when building my filter, search:

public class PersonService {
	private IPersonRepository _personRepository;

  ...

	public IEnumerable<Person> GetFemalePersonsOfGenerationXOfCityAsync( string city, CancellationToken cancellationToken ) {
		var spec = SpecBuilder<Person>
			.Create()
			.IsGenerationX()
			.IsIdentifiedAsFemale()
			.LivesOnCity(city);

		var result = _repository.SearchAsync(spec, cancellationToken);

		return result;
  }
}

So it's very clear that I'm looking for people with a female gender identity, from generation X and who live in the city I'm looking for.

🪄 Specifications

Specifications can be of three types and worked individually or in groups.

Applying all types can be done as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.And(x => x.PersonId != null)
	.Distinct()
	.Order(x => x.Name)
	.Order(x => x.Address)
	.Skip(10)
	.Take(10);

var result = enumerable
	.Specify(spec)
	.ToList();

🔽 Filters

Filters can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.And(x => x.PersonId != null);

var result = enumerable
	.Filter(spec)
	.ToList();

The following filters are available:

  • And
  • AndIf
  • Or
  • OrIf
  • Not

⬇️ Ordering

Ordering can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.Order(x => x.Name);

var result = enumerable
	.Sort(spec)
	.ToList();

The following orderings are available:

  • Order
  • OrderDescending
  • 📃 Pagination and post processing

Paginations and post processing can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.DistinctBy(x => x.Name)
	.Skip(10)
	.Take(10);

var result = enumerable
	.Paginate(spec)
	.ToList();

The following functions are available:

  • Skip
  • Take
  • DistinctBy
  • WithPagination - Convenient method using Pagination value object

WithPagination

You can also use the convenient WithPagination method that accepts a Pagination value object from Myth.Commons:

using Myth.ValueObjects;

var enumerable = Enumerable.Empty<Person>();
var pagination = new Pagination(2, 10); // Page 2, 10 items per page

var spec = SpecBuilder<Person>
	.Create()
	.And(x => x.PersonId != null)
	.Order(x => x.Name)
	.WithPagination(pagination);

var result = enumerable
	.Specify(spec)
	.ToList();

This replaces the manual calculation:

// Instead of:
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)

// Use:
.WithPagination(pagination)

Special cases:

  • Pagination.All (-1, -1): Returns all items without pagination
  • PageNumber <= 0: Treated as page 1
  • PageSize <= 0: Returns all items without pagination

Combining with Skip/Take: You can still combine WithPagination with additional Skip and Take operations:

var spec = SpecBuilder<Person>
	.Create()
	.WithPagination(pagination)  // Skip 10, Take 10 (page 2)
	.Skip(5)                     // Skip 5 more
	.Take(3);                    // Limit to 3 items total
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 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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Myth.Specification:

Package Downloads
Myth.Repository

Generic repository pattern interfaces with async support, specification integration, and pagination. Provides read/write separation, CRUD operations, and extensible repository contracts for clean data access architecture.

Myth.Repository.EntityFramework

Entity Framework Core implementations of repository pattern with Unit of Work, specification support, expression handling, and transaction management for robust data access with EF Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.1-preview.1 603 12/2/2025
4.2.0 423 11/30/2025
4.2.0-preview.1 59 11/29/2025
4.1.0 182 11/27/2025
4.1.0-preview.3 126 11/27/2025
4.1.0-preview.2 127 11/27/2025
4.1.0-preview.1 130 11/26/2025
4.0.1 171 11/22/2025
4.0.1-preview.8 144 11/22/2025
4.0.1-preview.7 148 11/22/2025
4.0.1-preview.6 134 11/22/2025
4.0.1-preview.5 200 11/21/2025
4.0.1-preview.4 204 11/21/2025
4.0.1-preview.3 209 11/21/2025
4.0.1-preview.2 236 11/21/2025
4.0.1-preview.1 242 11/21/2025
4.0.0 399 11/20/2025
4.0.0-preview.3 341 11/19/2025
4.0.0-preview.2 86 11/15/2025
4.0.0-preview.1 111 11/15/2025
3.10.0 188 11/15/2025
3.0.5-preview.15 148 11/14/2025
3.0.5-preview.14 217 11/12/2025
3.0.5-preview.13 223 11/12/2025
3.0.5-preview.12 223 11/11/2025
3.0.5-preview.11 223 11/11/2025
3.0.5-preview.10 223 11/11/2025
3.0.5-preview.9 212 11/10/2025
3.0.5-preview.8 90 11/8/2025
3.0.5-preview.7 90 11/8/2025
3.0.5-preview.6 92 11/8/2025
3.0.5-preview.5 91 11/8/2025
3.0.5-preview.4 58 11/7/2025
3.0.5-preview.3 138 11/4/2025
3.0.5-preview.2 135 11/4/2025
3.0.5-preview.1 135 11/4/2025
3.0.4 241 11/3/2025
3.0.4-preview.19 76 11/2/2025
3.0.4-preview.17 74 11/1/2025
3.0.4-preview.16 74 11/1/2025
3.0.4-preview.15 69 10/31/2025
3.0.4-preview.14 133 10/31/2025
3.0.4-preview.13 133 10/30/2025
3.0.4-preview.12 126 10/23/2025
3.0.4-preview.11 124 10/23/2025
3.0.4-preview.10 121 10/23/2025
3.0.4-preview.9 118 10/23/2025
3.0.4-preview.8 126 10/22/2025
3.0.4-preview.6 118 10/21/2025
3.0.4-preview.5 118 10/21/2025
3.0.4-preview.4 119 10/20/2025
3.0.4-preview.3 121 10/20/2025
3.0.4-preview.2 41 10/18/2025
3.0.4-preview.1 124 10/7/2025
3.0.3 247 8/30/2025
3.0.2 153 8/23/2025
3.0.2-preview.4 127 8/21/2025
3.0.2-preview.3 101 8/16/2025
3.0.2-preview.1 80 5/23/2025
3.0.1 4,547 3/12/2025
3.0.1-preview.2 158 3/11/2025
3.0.1-preview.1 89 2/5/2025
3.0.0.2-preview 146 12/10/2024
3.0.0.1-preview 185 6/29/2024
3.0.0 4,619 12/10/2024
3.0.0-preview 178 6/28/2024
2.0.0.17 2,338 12/15/2023
2.0.0.16 14,894 12/15/2023
2.0.0.15 304 12/15/2023
2.0.0.11 5,635 8/11/2022
2.0.0.10 2,984 7/20/2022
2.0.0.9 3,088 7/15/2022
2.0.0.8 3,105 7/12/2022
2.0.0.7 3,028 6/20/2022
2.0.0.6 3,145 5/23/2022
2.0.0.5 3,114 5/18/2022
2.0.0 3,197 2/17/2022