Giter Site home page Giter Site logo

dynamicquery.net's Introduction

DynamicQuery.Net

Finally! the package is available for dotnet core 2.0

Making query from the client side is an antipattern, but sometimes your project is a CRUD and you know that making a client-side query doesn't make a mess to your project, for these type of situations you can use DynamicQuery.Net.

How to use

Install Nuget Package

From Package Manager

$ Install-Package DynamicQuery.Net

From .Net CLI

$ dotnet add package DynamicQuery.Net

Dynamic Filtering:

Creating FilterInput object:

var filerInput = new FilterInput
                {
                    Operation = OperationTypeEnum.GreaterThan,
                    Property = "Date",
                    Type = InputTypeEnum.String,
                    Value = "2017/04/08"
                };

if you want to filter more than one field , you can create a List of FilterInput objects

var filerInput = new List<FilterInput>
            {
                new FilterInput
                {
                    Operation = OperationTypeEnum.GreaterThan,
                    Property = "Date",
                    Type = InputTypeEnum.String,
                    Value = "2017/04/08"
                }
            };

if you want to have more than one value for a single field, you can feed Value with a List:

var filerInput = new List<FilterInput>
            {
                new FilterInput
                {
                    Operation = OperationTypeEnum.NotEqual,
                    Property = "ClassNo",
                    Type = InputTypeEnum.Number,
                    Value = new List<object>{2,3,4}
                }
            };

Using FilterInput object

Now we can use our filterInput variable:

myQueryable = myQueryable.Filter(filerInput);

Dynamic Ordering

Creating OrderInput object:

For a single field:

 var orderItem = new OrderInput {Order = OrderTypeEnum.Desc, Property = "Date"};

For a List of fields:

 var orderInput = new List<OrderInput>
            {
                new OrderInput {Order = OrderTypeEnum.Desc, Property = "Date"},
                new OrderInput {Order = OrderTypeEnum.Asc, Property = "Name"},
                new OrderInput {Order = OrderTypeEnum.Asc, Property = "ID"}
            };

Using OrderInput object:

myQueryable = myQueryable.Order(orderInput);

Both of Filtering and Ordering:

Creating and Using OrderFilterInput object

var orderFilterInput = new OrderFilterInput 
                {
                    Filter = filerInput,
                    Order = orderInput
                }
               
 myQueryable = myQueryable.Filter(orderFilterInput); 

OrderFilterNonFilterInput

If you want to send some objects to the server that you won't use it as a Filter in IQueryable, you can use NonFilter Dictionary.

var nonFilterInput = new Dictionary<string, string>
            {
                {"TestName1", "TestValue1"},
                {"TestName2", "TestValue2"},
                {"TestName3", "TestValue3"}
            };

            var orderFilterNonFilterInput = new OrderFilterNonFilterInput()
            {
                Order = orderInput,
                Filter = filterInput,
                NonFilter = nonFilterInput
            };
		myQueryable = myQueryable.Filter(orderFilterNonFilterInput);

PagingInput

If you want to use paging in your filtering you can use PagingInput object :

 var paging = new PagingInput
            {
                Page = 2,
                Size = 10
            };
			
	myQueryable = myQueryable.Paging(paging);

DynamicQueryNetInput

All of the above-mentioned capabilities can be achieved by using a DynamicQueryNetInput object as a parameter to the Filter() extension method:

         var dynamicQueryNetInput = new DynamicQueryNetInput()
            {
                Order = orderInput,
                Filter = filterInput,
                NonFilter = nonFilterInput,
                Paging = paging
            };
			
	myQueryable = myQueryable.Filter(dynamicQueryNetInput);
	

Create simple REST APIs:

In the client side send a JSON to the server:

	{
      "Filter":[{"Property":"ContactNumber" , "Value":[2,3,4] , "Type":"Number" , "Operation":"Equal"}],
    	"Order":[{"Property":"Date" , "Order":"Desc"}],
    	"NonFilter":{"Calculate":"True"},
        "Paging":{"Page":3 , "Size":10}
	}

In the server just use it in .Filter() Method:

  public HttpResponseMessage Filter(DynamicQueryNetInput dynamicQueryNetInput)
  {
      return Request.CreateResponse(HttpStatusCode.OK, myQueryable.Filter(dynamicQueryNetInput));
  }

I Hope this will be Helpful

dynamicquery.net's People

Contributors

nasirjd 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.