https://github.com/skarllot/expressions
Provides base for specifications to a DDD model
https://github.com/skarllot/expressions
database ef-core martendb query repository specification
Last synced: 10 months ago
JSON representation
Provides base for specifications to a DDD model
- Host: GitHub
- URL: https://github.com/skarllot/expressions
- Owner: skarllot
- License: mit
- Created: 2023-02-19T12:31:05.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-31T13:55:53.000Z (10 months ago)
- Last Synced: 2025-08-31T15:35:29.149Z (10 months ago)
- Topics: database, ef-core, martendb, query, repository, specification
- Language: C#
- Homepage: https://fgodoy.me/Expressions/
- Size: 2.03 MB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Raiqub Expressions
_Raiqub.Expressions is a library that provides abstractions for creating specifications and query strategies using LINQ expressions. It also supports querying and writing to databases using various providers._
[](https://github.com/skarllot/Expressions/actions)
[](https://securityscorecards.dev/viewer/?uri=github.com/skarllot/Expressions)
[](https://codecov.io/gh/skarllot/Expressions)
[](https://dashboard.stryker-mutator.io/reports/github.com/skarllot/Expressions/main)
[](https://raw.githubusercontent.com/skarllot/Expressions/master/LICENSE)
[🏃 Quickstart](#quickstart) | [📖 Documentation](https://fgodoy.me/Expressions/) | [🔄 Migration](https://fgodoy.me/Expressions/migration-guide.html)
## Features
* Easily define and compose specifications to encapsulate business rules
* Create custom query strategies for flexible and efficient data retrieval
* Simplify database operations by using consistent abstractions
* Seamlessly integrate with Entity Framework Core for database interactions
* Utilize Marten providers for a NoSQL document database experience
* Built with .NET Standard 2.0, 2.1, and .NET 6.0
## NuGet Packages
* [](https://www.nuget.org/packages/Raiqub.Expressions/) **Raiqub.Expressions**: provides abstractions for creating specifications
* [](https://www.nuget.org/packages/Raiqub.Expressions.Reading/) **Raiqub.Expressions.Reading**: provides abstractions for creating query strategies and query sessions. Defines the `IDbQuerySession` and `IDbQuerySessionFactory` interfaces for querying from the database
* [](https://www.nuget.org/packages/Raiqub.Expressions.Writing/) **Raiqub.Expressions.Writing**: provides abstractions for creating write sessions and performing write operations. Defines the `IDbSession` and `IDbSessionFactory` interfaces for writing to the database
* [](https://www.nuget.org/packages/Raiqub.Expressions.EntityFrameworkCore/) **Raiqub.Expressions.EntityFrameworkCore**: implements sessions and factories using Entity Framework Core. Ideal for integrating with Entity Framework Core for database access
* [](https://www.nuget.org/packages/Raiqub.Expressions.Marten/) **Raiqub.Expressions.Marten**: implements sessions and factories using Marten library. Perfect for leveraging Marten's NoSQL document database capabilities
## Documentation
This README aims to give a quick overview of some Raiqub Expressions features. For deeper detail of available features, be sure also to check out [Documentation Page](https://fgodoy.me/Expressions/).
## Prerequisites
Before you begin, you'll need the following:
* .NET Standard 2.0 or 2.1, or .NET Core 6.0 installed on your machine
* An IDE such as Visual Studio, Visual Studio Code, or JetBrains Rider
* If you plan to use the reading package, have a database available for querying. If you intend to use the writing package, ensure you have a writable database to perform write operations
## Quickstart
To use Raiqub.Expressions in your project, follow these steps:
### Entity Framework Core
1. Install the required NuGet package(s) for the database provider you'll be using, such as **\`Microsoft.EntityFrameworkCore.SqlServer\`**
2. Install the **\`Raiqub.Expressions.EntityFrameworkCore\`** NuGet package
3. Register your DbContext by using **\`AddDbContextFactory\`** extension method
```csharp
services.AddDbContextFactory();
```
4. Register the session and session factories using the following extension method:
```csharp
services.AddEntityFrameworkExpressions()
.AddSingleContext();
```
### Marten
1. Install the **\`Marten\`** NuGet package
2. Install the **\`Raiqub.Expressions.Marten\`** NuGet package
3. Register the session and session factories using the following extension method:
```csharp
services.AddMartenExpressions()
.AddSingleContext();
```
### Using
Inject the appropriate session interface (`IDbQuerySession` for read sessions, `IDbSession` for read and write sessions) into your services, and use it read and write from/to database.
```csharp
public class YourService
{
private readonly IDbSession _dbSession;
public YourService(IDbSession dbSession)
{
_dbSession = dbSession;
}
// ...
}
```
You can also create specifications and query strategies. Here's an example of how to create a simple specification:
```csharp
public class CustomerIsActive : Specification
{
public override Expression> ToExpression()
{
return customer => customer.IsActive;
}
}
```
And here's an example of how to use the specification:
```csharp
// Assuming 'session' is of type IDbSession or IDbQuerySession and has been injected
var query = session.Query(new CustomerIsActive());
var customers = await query.ToListAsync();
```
## Contributing
If something is not working for you or if you think that the source file
should change, feel free to create an issue or Pull Request.
I will be happy to discuss and potentially integrate your ideas!
## License
This library is licensed under the [MIT License](./LICENSE).