LiteDB.Queryable 2.3.3

dotnet add package LiteDB.Queryable --version 2.3.3                
NuGet\Install-Package LiteDB.Queryable -Version 2.3.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LiteDB.Queryable" Version="2.3.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteDB.Queryable --version 2.3.3                
#r "nuget: LiteDB.Queryable, 2.3.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LiteDB.Queryable as a Cake Addin
#addin nuget:?package=LiteDB.Queryable&version=2.3.3

// Install LiteDB.Queryable as a Cake Tool
#tool nuget:?package=LiteDB.Queryable&version=2.3.3                

LiteDB.Queryable

An IQueryable wrapper implementation for LiteDB with additional async extensions.

This library allows the use of LINQ extensions methods for querying LiteDB.

The LiteQueryable<T> implementation is a warpper around a ILiteCollection<T> or a ILiteCollectionAsync<>. The LINQ extenions call are delegated to the equivalent methods of the LiteDB API.

Usage

Add the NuGet package to your project: LiteDB.Queryable

You can then aquire an IQueryable<T> instance using one of the available AsQueryable extension methods for ILiteCollection<T> or ILiteCollectionAsync<T>. The async variant is provided by the litedb-async project.

LiteDatabase database = new LiteDatabase("test.db");
ILiteCollection<Person> collection = database.GetCollection<Person>("people");
IQueryable<Person> queryable = collection.AsQueryable();

or

LiteDatabaseAsync database = new LiteDatabaseAsync("test.db");
ILiteCollectionAsync<Person> collection = database.GetCollection<Person>("people");
IQueryable<Person> queryable = collection.AsQueryable();

After that you can use the synchronous LINQ extensions with both variants and the asynchronous ones with the second variant.

Supported LINQ extensions

You can use the following methods to configure your query. Those methods are available in both variants.

  • Where
  • OrderBy
  • OrderByDescending
  • Skip
  • Take
  • Include
  • Select

The ThenBy/ThenByDescending methods and multiple OrderBy/OrderByDescending class are not supported at the moment, because LiteDB doesn't support multiple order exprssions.

Synchronous extenions

  • ToList
  • ToArray
  • ToDictionary
  • First
  • FirstOrDefault
  • Single
  • SingleOrDefault
  • Count
  • LongCount
  • Any
  • Sum
  • Average
  • Min
  • Max

Asynchronous extenions

  • ToListAsync
  • ToArrayAsync
  • ToDictionaryAsync
  • FirstAsync
  • FirstOrDefaultAsync
  • SingleAsync
  • SingleOrDefaultAsync
  • CountAsync
  • LongCountAsync
  • AnyAsync
  • SumAsync
  • AverageAsync
  • MinAsync
  • MaxAsync

Example

LiteDatabase database = new LiteDatabase("test.db");
ILiteCollection<Person> collection = database.GetCollection<Person>("people");
IQueryable<Person> queryable = collection.AsQueryable();

IList<Person> result = queryable
	.Where(x => x.Name.StartsWith("T"))
	.OrderBy(x => x.Age)
	.ToList();

Person result = queryable
	.Where(x => x.Age > 35)
	.FirstOrDefault();

string result = queryable
	.Where(x => x.Age > 35)
	.Select(x => x.Name)
	.FirstOrDefault();

or

LiteDatabaseAsync database = new LiteDatabaseAsync("test.db");
ILiteCollectionAsync<Person> collection = database.GetCollection<Person>("people");
IQueryable<Person> queryable = collection.AsQueryable();

IList<Person> result = await queryable
	.Where(x => x.Name.StartsWith("T"))
	.OrderBy(x => x.Age)
	.ToListAsync();

Person result = await queryable
	.Where(x => x.Age > 35)
	.FirstOrDefaultAsync();

string result = await queryable
	.Where(x => x.Age > 35)
	.Select(x => x.Name)
	.FirstOrDefaultAsync();

References

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
.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 is compatible. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on LiteDB.Queryable:

Package Downloads
Fluxera.Repository.LiteDB

A LiteDB repository implementation.

Magicube.Data.LiteDb

Package Description

GoLive.Saturn.Data.LiteDb

An experimental Rapid Prototype Development Framework in c#/.net core.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on LiteDB.Queryable:

Repository Stars
fluentcms/FluentCMS
ASP.NET Core Blazor Content Management System (CMS)