Skip to content

Commit

Permalink
Merge pull request #28 from ZEXSM/update-readme
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
ZEXSM committed Aug 23, 2020
2 parents 50ac53f + 9dc9377 commit 922be31
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OData.QueryBuilder
Library provides linq syntax and allows you to build OData queries based on the data model
The library primarily targets OData Version 4.01 and provides linq syntax for creating OData queries based on a data model.

[![Build Status](https://travis-ci.com/ZEXSM/OData.QueryBuilder.svg?branch=master)](https://travis-ci.com/ZEXSM/OData.QueryBuilder)
[![Coverage Status](https://coveralls.io/repos/github/ZEXSM/OData.QueryBuilder/badge.svg?branch=master)](https://coveralls.io/github/ZEXSM/OData.QueryBuilder?branch=master)
Expand All @@ -8,20 +8,30 @@ Library provides linq syntax and allows you to build OData queries based on the
## Benefits
* Expression is not used to `Compile()`, which generates `MSIL` code, which leads to memory leaks
* Support:
* nested `OData` extenders with a choice of filtering
* operators `all`, `any`, `in`
* date functions `date`
* string functions `contains`, `substringof`, `toupper`, `tolower`
* nested extenders with a choice of filtering
* operators
* [`in`](#in)
* [`any`](#any)
* [`all`](#all)
* functions
* date
* [`date`](#date)
* string and collection
* [`contains`](#contains)
* [`substringof`](#substringof)
* [`toupper`](#toupper)
* [`tolower`](#tolower)
* [`concat`](#concat)

## Installation
To install `OData.QueryBuilder` from `Visual Studio`, find `OData.QueryBuilder` in the `NuGet` package manager user interface or enter the following command in the package manager console:
```
Install-Package OData.QueryBuilder -Version 1.0.0
Install-Package OData.QueryBuilder
```

To add a link to the main dotnet project, run the following command line:
```
dotnet add -v 1.0.0 OData.QueryBuilder
dotnet add package OData.QueryBuilder
```

## Usage
Expand All @@ -31,13 +41,13 @@ dotnet add -v 1.0.0 OData.QueryBuilder
As soon as possible, create a new instance of the OData.QueryBuilder object indicating the data models and the base path:

```csharp
var odataQueryBuilder = new ODataQueryBuilder<Your entity model>(<base_url>);
var odataQueryBuilder = new ODataQueryBuilder<Your ODataContainerModel>(<Your base url>);
```

2. Specify the resource for which the request will be built

```csharp
odataQueryBuilder.For<Your data model>(s => s.<Your resource model>)
odataQueryBuilder.For<Your ODataEntityModel>(s => s.ODataEntity)
```

3. Select request type
Expand Down Expand Up @@ -138,7 +148,7 @@ var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
```
> $filter=IdRule ne null and IdRule eq null
```csharp
.Filter(s => s.ODataKind.OpenDate == DateTime.Today or s.ODataKind.OpenDate == new DateTime(2019, 7, 9)) or s.ODataKind.OpenDate == DateTime.Now)
.Filter(s => s.ODataKind.OpenDate == DateTime.Today || s.ODataKind.OpenDate == new DateTime(2019, 7, 9)) || s.ODataKind.OpenDate == DateTime.Now)
```
> $filter=ODataKind/OpenDate eq 2019-02-09T00:00:00Z or ODataKind/OpenDate eq 2019-02-09T00:00:00Z or ODataKind/OpenDate eq 2019-02-09T15:10:20Z
```csharp
Expand Down Expand Up @@ -189,21 +199,21 @@ var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")
## Usage operators

#### in
#### <a name="in"/> in

```csharp
.Filter((s, f, o) => o.In(s.ODataKind.ODataCode.Code, new[] { "123", "512" }) && o.In(s.IdType, new[] { 123, 512 }))
```
> $filter=ODataKind/ODataCode/Code in ('123','512') and IdType in (123,512)
#### any
#### <a name="any"/> any

```csharp
.Filter((s, f, o) => o.Any(s.ODataKind.ODataCodes, v => v.IdCode == 1)
```
> $filter=ODataKind/ODataCodes/any(v:v/IdCode eq 1)

#### all
#### <a name="all"/> all

```csharp
.Filter((s, f, o) => o.All(s.ODataKind.ODataCodes, v => v.IdActive))
Expand All @@ -212,44 +222,44 @@ var uri = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata")

## Usage date functions

#### date
#### <a name="date"/> date

```csharp
.Filter((s, f) => f.Date(s.Open) == DateTime.Today)
```
> $filter=date(Open) eq 2019-02-09T00:00:00Z

## Usage string functions
## Usage string and collections functions

#### contains
#### <a name="contains"/> contains

```csharp
.Filter((s, f) => f.Contains(s.ODataKind.ODataCode.Code, "W"))
```
> $filter=contains(ODataKind/ODataCode/Code,'W')

#### substringof
#### <a name="substringof"/> substringof

```csharp
.Filter((s, f) => f.SubstringOf("W", s.ODataKind.ODataCode.Code))
```
> $filter=substringof('W',ODataKind/ODataCode/Code)

#### toupper
#### <a name="toupper"/> toupper

```csharp
.Filter((s, f) => f.ToUpper(s.ODataKind.ODataCode.Code) == "TEST_CODE")
```
> $filter=toupper(ODataKind/ODataCode/Code) eq 'TEST_CODE'

#### tolower
#### <a name="tolower"/> tolower

```csharp
.Filter((s, f) => f.ToLower(s.ODataKind.ODataCode.Code) == "test_code")
```
> $filter=tolower(ODataKind/ODataCode/Code) eq 'test_code'

#### concat
#### <a name="concat"/> concat

```csharp
.Filter((s, f) => f.Concat(s.ODataKind.ODataCode.Code, "_1") == "test_code_1")
Expand Down Expand Up @@ -294,7 +304,7 @@ var builder = new ODataQueryBuilder<ODataInfoContainer>("http://mock/odata", new
var uri = builder
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Filter((s, f, o) => o.In(s.ODataKind.ODataCode.Code, new string[0]) or o.In(s.ODataKind.ODataCode.Code, null)
.Filter((s, f, o) => o.In(s.ODataKind.ODataCode.Code, new string[0]) || o.In(s.ODataKind.ODataCode.Code, null)
&& f.Contains(s.ODataKind.ODataCode.Code, default(string))
&& o.In(s.IdType, new[] { 123, 512 }))
.ToUri()
Expand Down
2 changes: 1 addition & 1 deletion src/OData.QueryBuilder/OData.QueryBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>odata;querybuilder;dotnet;charp</PackageTags>
<Authors>ZEXSM</Authors>
<Description>Library provides linq syntax and allows you to build OData queries based on the data model</Description>
<Description>The library primarily targets OData Version 4.01 and provides linq syntax for creating OData queries based on a data model.</Description>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down

0 comments on commit 922be31

Please sign in to comment.