aqua - aqua-accesscontrol 0.1.0-alpha-002

[Experimental] Query filters for linq expressions

PM> Install-Package aqua-accesscontrol -Version 0.1.0-alpha-002 -Source https://www.myget.org/F/aqua/api/v3/index.json

Copy to clipboard

> nuget.exe install aqua-accesscontrol -Version 0.1.0-alpha-002 -Source https://www.myget.org/F/aqua/api/v3/index.json

Copy to clipboard

> dotnet add package aqua-accesscontrol --version 0.1.0-alpha-002 --source https://www.myget.org/F/aqua/api/v3/index.json

Copy to clipboard
<PackageReference Include="aqua-accesscontrol" Version="0.1.0-alpha-002" />
Copy to clipboard
source https://www.myget.org/F/aqua/api/v3/index.json

nuget aqua-accesscontrol  ~> 0.1.0-alpha-002
Copy to clipboard

> choco install aqua-accesscontrol --version 0.1.0-alpha-002 --source https://www.myget.org/F/aqua/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "aqua" -SourceLocation "https://www.myget.org/F/aqua/api/v2"
Install-Module -Name "aqua-accesscontrol" -RequiredVersion "0.1.0-alpha-002" -Repository "aqua" -AllowPreRelease
Copy to clipboard

aqua-accesscontrol

GitHub license Github Workflow

branch AppVeyor Travis CI
main Build status Travis build Status
package nuget myget
aqua-accesscontrol NuGet Badge MyGet Pre Release

Description

This C# library provides extension methods for System.Linq.IQueryable<> and System.Linq.Expressions.Expression types, to apply query filters at various levels.

Features

Global Predicate

Global predicates apply to a query as a whole and must be satisfied for any results be returned.

Predicates can be based on progam logic and/or on expanded data query:

// base query
var query =
    from p in repo.Products
    select p;
// code based predicate
var result1 = query
    .Apply(Predicate.Create(() => true))
    .ToList();
// predicate based on data qeury
var result2 = query
    .Apply(Predicate.Create(() =>
        repo.Claims.Any(c =>
            c.Type == ClaimTypes.Tenant &&
            c.Value == "1" &&
            c.Subject == username)))
    .ToList();

Type Predicate

Type predicates apply to specific record types within a query by filtering out corresponding records that do not satisfy the condition.

The following predicate filters out records which have not TenantId equal to 1:

var query =
    from o in repo.Orders
    select new { o.Id };
var result = query
    .Apply(Predicate.Create<Order>(o => o.TenantId == 1))
    .ToList();

Property Predicate

Property predicates do not filter out records but allow property values to be returned only when specified conditions are satisfied.

The following predicate retrieves product prices only for records which have TenantId equal to 1, other records have the Price property set to its default vaule:

var query =
    from p in repo.Products
    select new { p.Id, p.Price };
var result = query
    .Apply(Predicate.Create<Product, decimal>(
        p => p.Price,
        p => p.TenantId == 1))
    .ToList();

Property Projection Predicate

Property projection predicates allow to project values of a certain property based on custom logic.

In the following example, a 10% discount is applied if TenantId is equal to 1:

var query =
    from p in repo.Products
    select new { p.Id, p.Price };

var result = query
    .Apply(Predicate.CreatePropertyProjection<Product, decimal>(
        p => p.Price,
        p => p.TenantId == 1 ? p.Price * 0.9m : p.Price))
    .ToList();
  • .NETStandard 2.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Christof Senn

Authors

Christof Senn

Project URL

https://github.com/6bee/aqua-accesscontrol

License

MIT

Info

286 total downloads
79 downloads for version 0.1.0-alpha-002
Download (20.56 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.0-beta-001 42.23 KB Fri, 14 Jun 2024 10:49:01 GMT 69
0.1.0-alpha-004 39.92 KB Tue, 11 Jun 2024 21:28:10 GMT 80
0.1.0-alpha-003 39.92 KB Tue, 11 Jun 2024 19:56:59 GMT 58
0.1.0-alpha-002 20.56 KB Fri, 23 Feb 2018 23:04:45 GMT 79