Vit.Linq
3.0.0
See the version list below for details.
dotnet add package Vit.Linq --version 3.0.0
NuGet\Install-Package Vit.Linq -Version 3.0.0
<PackageReference Include="Vit.Linq" Version="3.0.0" />
<PackageVersion Include="Vit.Linq" Version="3.0.0" />
<PackageReference Include="Vit.Linq" />
paket add Vit.Linq --version 3.0.0
#r "nuget: Vit.Linq, 3.0.0"
#:package Vit.Linq@3.0.0
#addin nuget:?package=Vit.Linq&version=3.0.0
#tool nuget:?package=Vit.Linq&version=3.0.0
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/VitormLib/Vit.Linq
| Build | NuGet |
|---|---|
Filter
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 NotContains 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.Filter.ComponentModel;
using Vit.Linq;
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, ornotor(a combination ofnotandor).
rulescan be nested FilterRules.
fieldcan be a nested property, such asidorjob.name.
operatorcan be one of the following:IsNull,IsNotNull,In,NotIn,=,!=,>,>=,<,<=,Contains,NotContains,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"
]
}
]
}
ExpressionTree
ExpressionTree 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.ExpressionTree;
namespace App
{
internal class Program2
{
static void Main(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.ExpressionTree.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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.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 | 2,636 | 11/4/2024 |
| 3.1.4 | 762 | 10/30/2024 |
| 3.1.3 | 844 | 10/10/2024 |
| 3.1.2 | 1,211 | 8/31/2024 |
| 3.1.1 | 756 | 8/29/2024 |
| 3.1.0 | 1,326 | 8/22/2024 |
| 3.0.3 | 1,183 | 8/8/2024 |
| 3.0.2 | 566 | 7/29/2024 |
| 3.0.1 | 702 | 7/22/2024 |
| 3.0.1-preview | 486 | 7/21/2024 |
| 3.0.0 | 549 | 7/14/2024 |
| 3.0.0-preview | 475 | 7/14/2024 |
| 2.2.25-preview | 377 | 7/14/2024 |
| 2.2.24-preview | 505 | 7/7/2024 |
| 2.2.23 | 282 | 7/3/2024 |
| 2.2.22 | 1,017 | 6/16/2024 |