NetDataQuery 1.0.0

dotnet add package NetDataQuery --version 1.0.0
                    
NuGet\Install-Package NetDataQuery -Version 1.0.0
                    
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="NetDataQuery" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetDataQuery" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NetDataQuery" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetDataQuery --version 1.0.0
                    
#r "nuget: NetDataQuery, 1.0.0"
                    
#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.
#addin nuget:?package=NetDataQuery&version=1.0.0
                    
Install NetDataQuery as a Cake Addin
#tool nuget:?package=NetDataQuery&version=1.0.0
                    
Install NetDataQuery as a Cake Tool

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:

Install-Package NetDataQuery

And in your Program.cs, register the repositories:

builder.Services.AddNetDataRepositories<YourDbContext>();

How it works

Define an interface that inherits from INetDataQuery<T> 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:

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

public interface ILineRepository : INetDataQuery<Line>
{
    Task<List<Line>> GetByActiveTrue();
    Task<List<Line>> GetByNameEquals(string name);
    Task<List<Line>> GetByNameAndActiveFalse(string name);
    Task<List<Line>> GetByBrandName(string name);
    Task<List<Line>> GetByBrandIconColorAndActiveTrueIncludeBrand(string color);
    Task<List<Line>> GetAllIncludeBrand();
    Task<Line> GetByIdEquals(int id); // Example of Task<Clase>
}

Use the repository

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:

GetByNameAndActiveTrue
GetByIdGreaterThanOrActiveFalse

Nested relationships

You can query nested properties of related entities:

GetByBrandName(string name)
GetByBrandIconColor(string color)

Includes

To include relationships, append Include{Property} at the end:

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.


Made with ?? by the .NET community

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 47 5/24/2025