2018-02-11 20:52:44 -05:00
|
|
|
# DynamicLinq
|
|
|
|
Adds extensions to Linq to offer dynamic queryables.
|
2018-02-11 21:42:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Samples
|
|
|
|
Complex Query
|
2018-02-11 21:44:19 -05:00
|
|
|
```csharp
|
2018-02-11 21:42:05 -05:00
|
|
|
query = query.Query(q =>
|
|
|
|
{
|
|
|
|
q.Compare("AuthorId", ConditionOperators.Equal, 1);
|
|
|
|
q.And(sq =>
|
|
|
|
{
|
|
|
|
sq.Compare("Content", ConditionOperators.Equal, "World");
|
|
|
|
sq.Or("Title", ConditionOperators.Contains, 3);
|
|
|
|
});
|
|
|
|
});
|
2018-02-11 21:42:55 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
Simple Query
|
2018-02-11 21:44:19 -05:00
|
|
|
```csharp
|
2018-02-11 21:42:55 -05:00
|
|
|
query.Where("FirstName", ConditionOperators.Equal, "David");
|
2018-02-11 21:44:19 -05:00
|
|
|
```
|
2018-02-12 04:18:42 -05:00
|
|
|
|
2018-02-12 05:20:15 -05:00
|
|
|
Simple Sorting
|
|
|
|
```csharp
|
|
|
|
query = query.OrderByDescending("AuthorId");
|
|
|
|
query = query.ThenBy("Id");
|
|
|
|
```
|
|
|
|
|
2018-02-12 04:18:42 -05:00
|
|
|
Using Query Builder
|
|
|
|
```csharp
|
|
|
|
// subject.
|
|
|
|
var posts = new List<Post>()
|
|
|
|
{
|
|
|
|
new Post { Id = 1, AuthorId = 1, Title = "Hello 1", Content = "World" },
|
|
|
|
new Post { Id = 2, AuthorId = 1, Title = "Hello 2", Content = "World" },
|
|
|
|
new Post { Id = 3, AuthorId = 2, Title = "Hello 3", Content = "World" },
|
|
|
|
};
|
|
|
|
|
|
|
|
// the query.
|
|
|
|
var query = posts.AsQueryable();
|
|
|
|
var queryBuilder = new QueryBuilder<Post>(query);
|
|
|
|
|
|
|
|
queryBuilder.Compare("AuthorId", ConditionOperators.Equal, 1);
|
|
|
|
queryBuilder.And(subQuery =>
|
|
|
|
{
|
|
|
|
subQuery.Compare("Content", ConditionOperators.Equal, "World");
|
|
|
|
subQuery.Or("Title", ConditionOperators.Contains, 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
query = queryBuilder.Build();
|
|
|
|
```
|