Skip to content

Linq extension to query couchbase lite repository (Linq to Expression)

License

Notifications You must be signed in to change notification settings

mathieumack/Linq2CouchBaseLiteExpression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linq2CouchBaseLiteExpression

Linq extension to query couchbase lite repository (Linq to Expression)

Writen in .net standard 2.0

IC

Quality Gate Status Build status NuGet version

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

/// <summary>
/// Entity object
/// </summary>
public class EntityObject
{
    public string Id { get; set; }

    public string Name { get; set; }

	public int Value { get; set; }
	
	public bool IsHuman { get; set; }
}
// Generate IExpression from a Lambda expression :
var resultFilter = Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name == "test");

This call will generate a Couchbase lite expression like this :

// 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 :
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name == "test");

// Or :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => "test" = e.Name );
  • You can use call static method withtout parameters only :
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name == CallToStaticMethod());

// Invalid :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name == CallToStaticMethod("Parameter"));

// Invalid :
var customObject = new CustomObject();
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name ==  customObject.NonPublicMethod());

// Invalid :
var customObject = new CustomObject();
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name ==  customObject.NonPublicMethodWithParameters("test"));
  • Only the methods are now supported : .Equals() or string.IsNullOrEmpty()
// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((e) => e.Name.Equals("test"));

// Valid :
Linq2CouchbaseLiteExpression.GenerateFromExpression<EntityObject>((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 :

"Buy Me A Coffee"

About

Linq extension to query couchbase lite repository (Linq to Expression)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages