https://github.com/mathieumack/linq2couchbaseliteexpression
Linq extension to query couchbase lite repository (Linq to Expression)
https://github.com/mathieumack/linq2couchbaseliteexpression
couchbase-lite linq
Last synced: about 1 year ago
JSON representation
Linq extension to query couchbase lite repository (Linq to Expression)
- Host: GitHub
- URL: https://github.com/mathieumack/linq2couchbaseliteexpression
- Owner: mathieumack
- License: mit
- Created: 2020-05-02T15:51:39.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-09-19T19:58:10.000Z (almost 3 years ago)
- Last Synced: 2025-03-27T12:46:49.498Z (over 1 year ago)
- Topics: couchbase-lite, linq
- Language: C#
- Size: 44.9 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Linq2CouchBaseLiteExpression
Linq extension to query couchbase lite repository (Linq to Expression)
Writen in .net standard 2.0
# IC
[](https://sonarcloud.io/dashboard?id=github-Linq2CouchBaseLiteExpression)
[](https://dev.azure.com/mackmathieu/Github/_build/latest?definitionId=17)
[](https://badge.fury.io/nu/Linq2CouchBaseLiteExpression)
# How to :
The class Linq2CouchbaseLiteExpression contains a unique method named GenerateFromExpression that generate an couchbase lite IExpression.
This generic method works on objects that are class.
First of all, install the plugin by the nuget package.
## Example
```csharp
///
/// Entity object
///
public class EntityObject
{
public string Id { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public bool IsHuman { get; set; }
}
```
```csharp
// Generate IExpression from a Lambda expression :
var resultFilter = Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == "test");
```
This call will generate a Couchbase lite expression like this :
```csharp
// Generate manually the IExpression :
Couchbase.Lite.Query.Expression.Property("Name").EqualTo(Couchbase.Lite.Query.Expression.String("test"))
```
## Supported operations
These operations are now supported
Function | Example
--- | ---
\> |
(e) => e.Value > 10
\< | (e) => e.Value < 10
\>= | (e) => e.Value >= 10
\>= | (e) => e.Value <= 10
== | (e) => e.Name == "test"
!= | (e) => e.Name != "test"
! | (e) => !e.IsHuman
.Equals | (e) => e.Name.Equals("test")
string.IsNullOrEmpty | (e) => string.IsNullOrEmpty(e.Name)
You can also combine conditions :
Function | Example
--- | ---
\|\| |
(e) => e.Name == "test" \|\| e.Name == "test 2"
\&\& | (e) => e.Value > 10 \&\& e.Name == "test 2"
## Lambda expression writing
The expression must respect some specific rules :
* You can set field object at left or at right of the operation :
```csharp
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == "test");
// Or :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => "test" = e.Name );
```
* You can use call static method withtout parameters only :
```csharp
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == CallToStaticMethod());
// Invalid :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == CallToStaticMethod("Parameter"));
// Invalid :
var customObject = new CustomObject();
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == customObject.NonPublicMethod());
// Invalid :
var customObject = new CustomObject();
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name == customObject.NonPublicMethodWithParameters("test"));
```
* Only the methods are now supported : .Equals() or string.IsNullOrEmpty()
```csharp
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => e.Name.Equals("test"));
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression((e) => string.IsNullOrEmpty(e.Name);
```
# Contribute
You want more ? Feel free to create an issue or contribute by adding new functionnalities by forking the project and create a pull request.
And if you like this project, don't forget to star it !
You can also support me with a coffee :
[](https://www.buymeacoffee.com/mathieumack)