https://github.com/mgernand/litedb.queryable
A queryable wrapper implementation for LiteDB with additional async extensions.
https://github.com/mgernand/litedb.queryable
async dotnet dotnet-core dotnet7 linq litedb netstandard netstandard20 netstandard21 queryable
Last synced: 2 months ago
JSON representation
A queryable wrapper implementation for LiteDB with additional async extensions.
- Host: GitHub
- URL: https://github.com/mgernand/litedb.queryable
- Owner: mgernand
- License: mit
- Created: 2022-11-29T19:57:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-03T11:53:01.000Z (7 months ago)
- Last Synced: 2025-03-15T05:25:11.993Z (7 months ago)
- Topics: async, dotnet, dotnet-core, dotnet7, linq, litedb, netstandard, netstandard20, netstandard21, queryable
- Language: C#
- Homepage:
- Size: 76.2 KB
- Stars: 24
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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``` implementation is a warpper around a ```ILiteCollection```
or a ```ILiteCollectionAsync<>```. The LINQ extenions call are delegated to the
equivalent methods of the LiteDB API.## This repository was moved to https://codeberg.org/mgernand/LiteDB.Queryable
## Usage
Add the NuGet package to your project: ```LiteDB.Queryable```
You can then aquire an ```IQueryable``` instance using one of the available ```AsQueryable```
extension methods for ```ILiteCollection``` or ```ILiteCollectionAsync```. The async
variant is provided by the [litedb-async](https://github.com/mlockett42/litedb-async) project.```C#
LiteDatabase database = new LiteDatabase("test.db");
ILiteCollection collection = database.GetCollection("people");
IQueryable queryable = collection.AsQueryable();
```or
```C#
LiteDatabaseAsync database = new LiteDatabaseAsync("test.db");
ILiteCollectionAsync collection = database.GetCollection("people");
IQueryable 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
- SelectThe ```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
```C#
LiteDatabase database = new LiteDatabase("test.db");
ILiteCollection collection = database.GetCollection("people");
IQueryable queryable = collection.AsQueryable();IList 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
```C#
LiteDatabaseAsync database = new LiteDatabaseAsync("test.db");
ILiteCollectionAsync collection = database.GetCollection("people");
IQueryable queryable = collection.AsQueryable();IList 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
- [LiteDB](https://github.com/mbdavid/LiteDB)
- [LiteDB Async](https://github.com/mlockett42/litedb-async)
- [Entity Framework Core](https://github.com/dotnet/efcore)