Vit.Linq 3.1.5

dotnet add package Vit.Linq --version 3.1.5                
NuGet\Install-Package Vit.Linq -Version 3.1.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Vit.Linq" Version="3.1.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Vit.Linq --version 3.1.5                
#r "nuget: Vit.Linq, 3.1.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Vit.Linq as a Cake Addin
#addin nuget:?package=Vit.Linq&version=3.1.5

// Install Vit.Linq as a Cake Tool
#tool nuget:?package=Vit.Linq&version=3.1.5                

Vit.Linq

Vit.Linq provides two tools for handling Expressions: Filter and ExpressionTree.

  • Filter can convert between FilterRule and Expression Predicate, allowing for dynamic filtering of result sets using JSON data.
  • ExpressionTree facilitates the conversion between ExpressionNode and Expression, enabling transformations between data and code.

    Note: Since non-primitive types cannot be transmitted via data formats, the conversion may not be fully equivalent, and some type information might be lost.

source address: https://github.com/Vit-Orm/Vit.Linq

alternate text is missing from this package README image
alternate text is missing from this package README image alternate text is missing from this package README image

Build NuGet
alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

FilterRules

FilterRule can express logical combinations (And / Or / Not) and basic logical evaluations (such as numerical comparisons / string matching / null checks, etc.). The complete set of features is as follows:

  • And
  • Or
  • Not
  • NotAnd
  • NotOr
  • Logical Judgement
    • [object] is null (==null) / is not null (!=null)
    • [numeric] compare: == != > >= < ⇐
    • [string] compare: Contains NotContain StartsWith EndsWith IsNullOrEmpty IsNotNullOrEmpty
    • [array] contains: In / NotIn
    • custom operator

Example

Install necessary packages:

dotnet add package Vit.Linq
dotnet add package Vit.Core

Create console project and edit Program.cs

code address: Program.cs

using Vit.Core.Module.Serialization;
using Vit.Linq;
using Vit.Linq.FilterRules.ComponentModel;

namespace App
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var users = new[] { new { id = 1, name = "name1" }, new { id = 2, name = "name2" } };

            var strRule = "{\"field\":\"id\",  \"operator\": \"=\",  \"value\": 1 }";
            var rule = Json.Deserialize<FilterRule>(strRule);

            var result = users.AsQueryable().Where(rule).ToList();

            var count = result.Count;
        }
    }
}


FilterRule Format

FilterRule is JSON-formatted data where the condition can be and, or, not, notand, or notor (a combination of not and or).
rules can be nested FilterRules.
field can be a nested property, such as id or job.name.
operator can be one of the following: IsNull, IsNotNull, In, NotIn, =, !=, >, >=, <, <=, Contains, NotContain, StartsWith, EndsWith, IsNullOrEmpty, IsNotNullOrEmpty, etc.

{
  "condition": "and",
  "rules": [
    {
      "field": "job.name",
      "operator": "!=",
      "value": "name987_job1"
    },
    {
      "field": "name",
      "operator": "IsNotNull"
    },
    {
      "field": "name",
      "operator": "NotIn",
      "value": [
        "name3",
        "name4"
      ]
    }
  ]
}

ExpressionNodes

ExpressionNode enables the transformation between ExpressionNode (data) and Expression (code), allowing for data and code interchangeability. It supports all query-related expressions (excluding functionalities like Expression.Assign).

Example

Install necessary packages:

dotnet add package Vit.Linq
dotnet add package Vit.Core

Create console project and edit Program.cs

code address: Program.cs

using Vit.Core.Module.Serialization;
using Vit.Linq;
using Vit.Linq.ExpressionNodes;

namespace App
{
    internal class Program2
    {
        static void Main2(string[] args)
        {
            var users = new[] { new User(1), new User(2), new User(3), new User(4) };
            var query = users.AsQueryable();

            var queryExpression = users.AsQueryable().Where(m => m.id > 0).OrderBy(m => m.id).Skip(1).Take(2);

            #region #1 Expression to ExpressionNode (Code to Data)
            var node = ExpressionConvertService.Instance.ConvertToData_LambdaNode(queryExpression.Expression);
            var strNode = Json.Serialize(node);
            #endregion

            #region #2 ExpressionNode to QueryAction
            var queryAction = new Vit.Linq.ExpressionNodes.Query.QueryAction(node);
            var strQuery = Json.Serialize(queryAction);
            #endregion

            // #3 compile code
            var predicate = ExpressionConvertService.Instance.ConvertToCode_PredicateExpression<User>(queryAction.filter);
            //var lambdaExp = (Expression<Func<Person, bool>>)convertService.ToLambdaExpression(queryAction.filter, typeof(User));

            var rangedQuery = query.Where(predicate).OrderBy(queryAction.orders);
            if (queryAction.skip.HasValue)
                rangedQuery = rangedQuery.Skip(queryAction.skip.Value);
            if (queryAction.take.HasValue)
                rangedQuery = rangedQuery.Take(queryAction.take.Value);


            var result = rangedQuery.ToList();
            var count = result.Count;

        }

        class User
        {
            public User(int id) { this.id = id; this.name = "name" + id; }
            public int id { get; set; }
            public string name { get; set; }
        }
    }
}

Examples:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Vit.Linq:

Package Downloads
Vit.Orm.EntityFramework

entensions for EntityFramework

Vitorm

Vitorm : simple orm

Vitorm.ElasticSearch.QueryBuilder

Tool to convert FilterRule or ExpressionNode to ElasticSearch Query Request

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.5 601 11/4/2024
3.1.4 384 10/30/2024
3.1.3 462 10/10/2024
3.1.2 742 8/31/2024
3.1.1 432 8/29/2024
3.1.0 852 8/22/2024
3.0.3 728 8/8/2024
3.0.2 237 7/29/2024
3.0.1 403 7/22/2024
3.0.1-preview 271 7/21/2024
3.0.0 283 7/14/2024
3.0.0-preview 250 7/14/2024
2.2.25-preview 216 7/14/2024
2.2.24-preview 282 7/7/2024
2.2.23 111 7/3/2024
2.2.22 609 6/16/2024
2.2.21 204 2/2/2024
2.2.20 152 2/1/2024
2.2.19 162 1/31/2024
2.2.18 317 1/22/2024
2.2.17 172 1/19/2024
2.2.16 118 1/17/2024
2.2.15 123 1/17/2024
2.2.14 129 1/12/2024
2.2.13 244 12/21/2023
2.2.12 355 7/30/2023
2.2.11 324 5/19/2023
2.2.10 1,109 7/26/2022
2.2.10-preview6 309 4/5/2022
2.2.10-preview5 344 4/2/2022
2.2.9 1,304 2/19/2022
2.2.8 1,025 9/27/2021
2.2.7 1,118 9/9/2021
2.2.6 1,157 8/22/2021
2.2.5 840 8/21/2021
2.2.4 829 8/18/2021
2.2.2 1,248 6/5/2021
2.2.1.658 1,123 5/27/2021
2.2.0.635 1,150 5/20/2021
2.1.4.514 1,686 4/22/2021
2.1.3.499 1,741 4/20/2021
2.1.1.602 1,705 4/15/2021
2.1.1.499 1,622 2/22/2021
2.1.1.494 1,637 2/8/2021
2.1.1.487 1,642 2/7/2021
2.1.1.482 1,620 2/3/2021
2.1.1.478 1,725 2/2/2021
2.1.1.476 1,725 1/29/2021
2.1.1.461 1,701 1/22/2021
2.1.1.453 1,792 1/15/2021
2.1.1.425 1,043 11/24/2020
2.1.1.423 1,087 11/24/2020
2.1.1.419 1,120 11/11/2020
2.1.1.413 1,290 11/11/2020
2.1.1.410 1,149 10/12/2020
2.1.1.404 1,120 9/28/2020
2.1.1.392 1,301 9/16/2020
2.1.1.384 1,147 8/27/2020
2.1.1.378 1,350 8/8/2020
2.1.1.359 1,128 7/7/2020
2.1.1.352 1,243 6/17/2020
2.1.1.348 1,187 5/29/2020
2.1.1.345 1,307 5/6/2020
2.1.1.341 1,261 4/20/2020
2.1.1.334 1,242 4/10/2020
2.1.1.324 1,029 4/3/2020
2.1.1.322 1,255 4/1/2020
2.1.1.319 1,196 3/31/2020
2.1.1.318 1,198 3/25/2020
2.1.1.315 1,318 3/23/2020
2.1.1.312 1,211 3/17/2020
2.1.1.307 1,295 3/12/2020
2.1.1.304 1,234 3/10/2020
2.1.1.300 1,168 3/9/2020
2.1.1.296 1,210 3/4/2020
2.1.1.291 1,177 3/3/2020
2.1.1.290 1,443 3/2/2020
2.1.1.250 1,221 2/17/2020