Coder Social home page Coder Social logo

smartorderby's Introduction

SmartOrderBy

It intelligently sorts a sequence of items in a simple and practical way.

GitHub Workflow Status (with event) SmartOrderBy Nuget SmartOrderBy Nuget

SmartOrderBy is a method that aims to make the Queryable.OrderBy method smarter and is based on the foundations of .NET.

I would be very happy if you could star โญ the project.

Quick Start

The usage of SmartOrderBy is quite simple.

  1. Install SmartOrderBy NuGet package from here.
PM> Install-Package SmartOrderBy
  1. We add our Sorting object to our Request object.
public Sorting OrderBy { get; set; }

The structure of the Sorting object;

public class Sorting
{
    public string Name { get; set; }
    public string OrderType { get; set; }
}

Name => The name of the field to be sorted.

OrderType => The type of the order. It can be specified as "asc", "ascending", "a" or "desc", "descending", "d".

  1. And we sort intelligently. And that's it.
[HttpPost("/publishers")]
public IActionResult GetPublishers(PublisherRequest request)
{
    var result = _context.Publishers
        .Include(x => x.Books)
        .ThenInclude(x => x.Author)
        .OrderBy(request.OrderBy)
        .ToList();

    return Ok(result);
}

Details

If you want to specify the name of the field you want to sort differently from the field in the entity, you need to map it.

๐Ÿ‘‰ You can access the sample domain structure here. ๐Ÿ‘ˆ

For example, if you want to make a sorting with the name bookId according to the Id field of the Book entity in Publisher, you will need to make a mapping as follows.

OrderByMapper.Map<Publisher, Book>("bookId", x => x.Id);

Or if you want to make a sort with the authorAge name according to the Age field of the Author entity in the Book entity in Publisher;

OrderByMapper.Map<Publisher, Book, Author>("authorAge", x => x.Age);

โญ The important thing here is to specify the relevant entities in Map<TSource,T1,T2,...> respectively until you reach the sort field.

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.