Skip to content

Commit

Permalink
Added readme-nuget.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fiseni committed Sep 27, 2024
1 parent 3561f99 commit 0af6626
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
3 changes: 2 additions & 1 deletion QuerySpecification.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\ci.yml = .github\workflows\ci.yml
clean.sh = clean.sh
Directory.Packages.props = Directory.Packages.props
tests\Directory.Build.props = tests\Directory.Build.props
src\Directory.Build.props = src\Directory.Build.props
Directory.Packages.props = Directory.Packages.props
exclusion.dic = exclusion.dic
LICENSE.txt = LICENSE.txt
readme-nuget.md = readme-nuget.md
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
run-tests.sh = run-tests.sh
Expand Down
71 changes: 71 additions & 0 deletions readme-nuget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
A .NET library for building query specifications.
- [Pozitron.QuerySpecification](https://www.nuget.org/packages/Pozitron.QuerySpecification)
A base package containing the core functionality, in-memory evaluators, and validators.
- [Pozitron.QuerySpecification.EntityFrameworkCore](https://www.nuget.org/packages/Pozitron.QuerySpecification.EntityFrameworkCore)
An `EntityFramework Core` plugin to the base package. It contains EF specific evaluators.

## Usage

Create your specification classes by inheriting from the `Specification<T>` class, and use the builder `Query` to build your queries in the constructor.

```csharp
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec(int age, string nameTerm)
{
Query
.Where(x => x.Age > age)
.Like(x => x.Name, $"%{nameTerm}%")
.Include(x => x.Addresses)
.ThenInclude(x => x.Contact)
.OrderBy(x => x.Id)
.ThenBy(x => x.Name)
.Skip(10)
.Take(10)
.AsSplitQuery();
}
}
```

Apply the specification to `DbSet<T>` or to any `IQueryable<T>` source.

```csharp
var spec = new CustomerSpec(30, "John");

List<Customer> result = await _context
.Customers
.WithSpecification(spec)
.ToListAsync();
```

### Projections

The specification can be used to project the result into a different type. Inherit from `Specification<T, TResult>` class, where TResult is the type you want to project into. This offers strongly typed experience in the builder and during the evaluation.

```csharp
public class CustomerDtoSpec : Specification<Customer, CustomerDto>
{
public CustomerDtoSpec(int age, string nameTerm)
{
Query
.Where(x => x.Age > age)
.Like(x => x.Name, $"%{nameTerm}%")
.OrderBy(x => x.Name)
.Select(x => new CustomerDto(x.Id, x.Name));
}
}
```

Apply the specification to `DbSet<T>` or any `IQueryable<T>` source.

```csharp
var spec = new CustomerSpec(30, "John");

List<CustomerDto> result = await _context
.Customers
.WithSpecification(spec)
.ToListAsync();
```

## Give a Star! :star:
If you like or are using this project please give it a star. Thanks!
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReadmeFile>readme-nuget.md</PackageReadmeFile>
<PackageIconUrl>https://pozitrongroup.com/PozitronLogo.png</PackageIconUrl>
<PackageIcon>pozitronicon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<None Include="../../pozitronicon.png" Pack="true" PackagePath="\" />
<None Include="../../README.md" Pack="true" PackagePath="\" />
<None Include="../../readme-nuget.md" Pack="true" PackagePath="\" />
<None Include="../../LICENSE.txt" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
</Project>

0 comments on commit 0af6626

Please sign in to comment.