Git Product home page Git Product logo

edennis.netcore.linqtools's Introduction

EDennis.NetCore.LinqTools

Dynamically applies filtering, sorting, and paging (and optional selecting) to IEnumerable, IQueryable, and DbSet objects using either a JSON-friendly spec or a query-string spec.

The Full Filtering/Sorting/Paging Spec

The full specification for filtering, sorting, paging, and selecting is represented by a simple, JSON-friendly hierarchical structure. The library also supports a more simplified spec for query-string processing (see below).

Example Specification as JSON

{
   filter: 
   [
      [
         {
            property: "Name",
            operation: "Eq",
            stringValue: "AliceBlue"
         }
      ],
      [
         {
            property: "Red",
            operation: "Eq",
            stringValue: "0"
         },
         {
            property: "Blue",
            operation: "Eq",
            stringValue: "0"
         }
      ]
   ],
   sort: 
   [
      {
         property: "Red",
         direction: "Ascending"
      },
      {
         property: "Green",
         direction: "Ascending"
      }
   ],
   page: 
   {
      pageNumber: 2,
      pageSize: 3
   },
   select: [ "Name", "DateCreated"]
}

Filtering Spec

The filtering specification is a two-dimensional array of objects, which can be interpreted as a filter table. Each row in the filter table (an outer array element) represents an intersection (AND-ed) over one or more expression units. Each expression unit consists of a property name, and operation, and a literal value (as a string). Currently supported operations are: Eq, Lt, Le, Gt, Ge, Contains, StartsWith, and EndsWith. All filter rows are unioned (OR-ed) to provide the complete filter. This is analogous to the filtering table in the design mode of a Microsoft Access query.

In the above example, we select all objects where Name = "AliceBlue" or where both Red and Blue properties were equal to zero.

Sorting Spec

The sorting specification is a one-dimensional array of objects, where each object provides a property name and sort direction.

In the above example, we sort by Red (ascending) and then by Green (ascending)

Paging Spec

The paging specification is a single object consisting of a page number and page size.

In the above example, we return the second page, where each page holds three objects.

Selecting Spec

The optional selecting specification is a single array consisting of property names to include.

In the above example, we select the Name and DateCreated properties. Note: selection will return an IQueryable whose member type is anonymous, rather than an IQueryable of the source element type.

The Simplified Filtering/Sorting/Paging Spec Using a Query String

The library also supports a Contoso-University-Project-inspired spec for query-string processing of filtering, sorting, paging, and optional selecting. Filtering is specified by a searchString query parameter (which uses the Contains operation). Sorting is specified by a sortOrder query parameter. The value of the sortOrder parameter is the name of the field to sort on, with an optional "_desc" suffix. (There is a constructor overload for mapping sortOrder parameter values to field names and sort direction, just in case this kind of flexibility is required.) Paging is accomplished with pageNumber and pageSize query parameters. Selecting is accomplished with either an array of properties (if hardcoding on the server side) or a comma-delimited string (if passed in via URL).

Other Examples

The test project in this solution includes examples of filtering, sorting, and paging (and optional selecting) using the full (JSON body) spec and filtering, sorting, and paging using the simplified (query string) spec.

edennis.netcore.linqtools's People

Contributors

denmitchell avatar denniscmitchell avatar

Watchers

 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.