Coder Social home page Coder Social logo

bubdm / system.linq.dynamic.apifilter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from essvisionab/system.linq.dynamic.apifilter

0.0 0.0 0.0 75 KB

Portable core-level .NET class library. Parses and applies query string filters to be used on data entities or in-memory collections.

License: Other

C# 100.00%

system.linq.dynamic.apifilter's Introduction

System.Linq.Dynamic.ApiFilter

Portable core-level .NET class library. Parses and applies query string filters to be used on data entities or in-memory collections.

Filter example1:

http://example.com/documents?filter=contacts.name~adam

Filter for document resources that has a name containing 'adam'.

Filter example2:

http://example.com/documents?filter=contacts.name~adam;contacts.email~com

Filter for document resources that has a contact with a name containing 'adam' and an email containing 'com'.

Special case example1

http://example.com/documents?filter=folderid:{guid}

Filter for documents directly in specified folder

Special case example2

http://example.com/documents?filter=folderid~{guid}

Filter for documents in specified folder and its children

Inclusive or equal filter example:

http://example.com/documents?filter=name:(a, b, c)

Filter for document resources wich names are 'a', 'b' or 'c'.

Inclusive or like filter example:

http://example.com/documents?filter=name~(a, b, c)

Filter for document resources wich names contains 'a', 'b' or 'c'.

Backend simple usage example:

// Create the filter provider with a predicate factory
var factory = new PredicateBuilderFactory();
var provider = new FilterProvider(factory);

using(vad db = new SomeDbContext())
{
    var q = db.SomeTable.AsQueryable();
    // Apply query filters. Under the hood System.Linq.Dynamic is used
    q = provider.ApplyFilter(q, filter);
    // Materialize the data
    return q.ToArray();
}

The main service to use in any web app is IFilterProvider that is defined like so:

    public interface IFilterProvider
    {
        IQueryable<TEntity> ApplyFilter<TEntity>(IQueryable<TEntity> query, string filters);
        IQueryable<TEntity> ApplyFilter<TEntity>(IQueryable<TEntity> query, IEnumerable<Filter> filters);
    }

Filter provider is extendable through PredicateBuilderFactory's method AddBuilderType:

    public void AddBuilderType(string targetTypeName, Type builderType){...}
    public void AddBuilderType<T>(string targetTypeName){...}

Where targetTypeName is the fullname of the data type and builderType is an implementation of IPredicateBuilder extending the abstract PredicateBuilder<TEntity> base class.

supported operands and there sql equivalent

operands sql equivalent data types
: equal all data types
<> not equal all data types
~ like string
< smaller than all data types exept string
<: smaller than or equal all data types exept string
> greater than all data types exept string
>: greater than or equal all data types exept string
:(a,b...) inclusive or equal. -> q.Where("field == @0 || field == @1 ...") all data types
~(a,b...) inclusive or like. -> q.Where("field.Contains(@0) || field.Contains(@1)...") string
; and (combines filters) n/a

system.linq.dynamic.apifilter's People

Contributors

theblomskog avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.