https://github.com/estuardodev/netdataquery
https://github.com/estuardodev/netdataquery
csharp dotnet netcore
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/estuardodev/netdataquery
- Owner: estuardodev
- License: mit
- Created: 2025-06-09T13:48:40.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-10T20:45:27.000Z (12 months ago)
- Last Synced: 2026-03-17T09:36:18.858Z (4 months ago)
- Topics: csharp, dotnet, netcore
- Language: C#
- Homepage: https://www.nuget.org/packages/NetDataQuery
- Size: 145 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NetDataQuery
NetDataQuery is an open-source library for .NET that allows dynamic queries to be defined through method names, simplifying data access without writing LINQ expressions manually.
---
## Installation
Install the library from NuGet:
```bash
Install-Package NetDataQuery
```
And in your `Program.cs`, register the repositories:
```csharp
builder.Services.AddNetDataRepositories();
```
---
## How it works
Define an interface that inherits from `INetDataQuery` and declare your query methods using `GetBy...`, `FindBy...`, `ReadBy...`, or `QueryBy...`.
The library parses the method name and automatically generates the corresponding LINQ expression.
---
## Usage Example
Assuming the class `Line`:
```csharp
public class Line
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public bool Active { get; set; }
public int BrandId { get; set; }
public Brand? Brand { get; set; }
}
public class Brand
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? IconColor { get; set; }
public bool Active { get; set; }
}
```
### Define a repository
```csharp
public interface ILineRepository : INetDataQuery
{
Task> GetByActiveTrue();
Task> GetByNameEquals(string name);
Task> GetByNameAndActiveFalse(string name);
Task> GetByBrandName(string name);
Task> GetByBrandIconColorAndActiveTrueIncludeBrand(string color);
Task> GetAllIncludeBrand();
Task GetByIdEquals(int id); // Example of Task
}
```
### Use the repository
```csharp
var activeLines = await _lineRepository.GetByActiveTrue();
var byName = await _lineRepository.GetByNameEquals("Special");
var byBrand = await _lineRepository.GetByBrandName("Toyota");
var withInclude = await _lineRepository.GetByBrandIconColorAndActiveTrueIncludeBrand("red");
```
---
## Supported Conventions
### Method types
- `GetBy`, `FindBy`, `ReadBy`, `QueryBy`
- `GetAll`, `FindAll`, etc.
### Supported Conditions
| Suffix | Example | Generated LINQ Expression |
|----------------|------------------------------------|--------------------------------------|
| Equals (default) | `GetByName(string)` | `x => x.Name == value` |
| True | `GetByActiveTrue()` | `x => x.Active == true` |
| False | `GetByActiveFalse()` | `x => x.Active == false` |
| GreaterThan | `GetByIdGreaterThan(int id)` | `x => x.Id > id` |
| LessThan | `GetByIdLessThan(int id)` | `x => x.Id < id` |
You can combine conditions using `And` and `Or`:
```csharp
GetByNameAndActiveTrue
GetByIdGreaterThanOrActiveFalse
```
### Nested relationships
You can query nested properties of related entities:
```csharp
GetByBrandName(string name)
GetByBrandIconColor(string color)
```
### Includes
To include relationships, append `Include{Property}` at the end:
```csharp
GetByBrandNameIncludeBrand
GetAllIncludeBrand
GetByActiveTrueIncludeBrand
```
**Important:** `Include` statements must appear **at the end** of the method name.
---
## Roadmap (future)
- Support for `ThenInclude`
- Automatic interface and controller generation (scaffolding-style)
- Sorting (`OrderBy`, `OrderByDesc`)
- Collection queries (`In`, `Contains`)
---
## Contributions
This project is open-source. You can create issues, PRs, or suggest improvements. Contributions are welcome!
---
## License
This project is under the MIT License.