QueryFlow 1.0.0
dotnet add package QueryFlow --version 1.0.0
NuGet\Install-Package QueryFlow -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="QueryFlow" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QueryFlow" Version="1.0.0" />
<PackageReference Include="QueryFlow" />
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 QueryFlow --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QueryFlow, 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.
#:package QueryFlow@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=QueryFlow&version=1.0.0
#tool nuget:?package=QueryFlow&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
QueryFlow
A powerful and flexible query builder library for .NET that allows you to build database queries dynamically and translate them to different query languages.
Features
- Type-safe query building with LINQ-like syntax
- Dynamic query building with runtime field specification
- Multiple database support (SQL, MongoDB, and more)
- Fluent API for intuitive query construction
- Conditional query building for dynamic filtering
- Advanced operations: joins, pagination, ordering, grouping
- Query translation to SQL, MongoDB, and other formats
Installation
dotnet add package QueryFlow
Quick Start
Basic Usage
using QueryFlow;
// Type-safe query building
var query = QueryFlow.From<Product>()
.Where(p => p.Price > 100)
.Where(p => p.Category == "Electronics")
.OrderBy(p => p.Name)
.Take(10);
// Apply to IQueryable
var results = query.ApplyTo(dbContext.Products).ToList();
// Or translate to SQL
string sql = query.ToSql();
// SELECT * FROM Product WHERE Price > 100 AND Category = 'Electronics' ORDER BY Name ASC LIMIT 10
Dynamic Query Building
// Build queries with runtime field names
var dynamicQuery = QueryFlow.From(typeof(Product))
.Where("Price", 100, ComparisonOperator.GreaterThan)
.Where("Category", "Electronics")
.OrderBy("Name")
.Paginate(page: 1, pageSize: 20);
// Convert to SQL
string sql = dynamicQuery.ToSql();
Conditional Filtering
var query = QueryFlow.From<Product>();
// Only add filter if condition is true
query.Where(userInput.MinPrice.HasValue, p => p.Price >= userInput.MinPrice.Value)
.Where(!string.IsNullOrEmpty(userInput.Category), p => p.Category == userInput.Category)
.Where(userInput.InStock, p => p.StockQuantity > 0);
Complex Queries
var query = QueryFlow.From<Order>()
.Join<Customer>(o => o.CustomerId, c => c.Id)
.Where(o => o.OrderDate >= DateTime.Now.AddDays(-30))
.OrWhere(o => o.Priority == "High")
.Select("Id", "OrderDate", "Total")
.OrderBy(o => o.OrderDate)
.ThenBy(o => o.Total)
.Distinct()
.Paginate(page: 2, pageSize: 50);
MongoDB Translation
var query = QueryFlow.From<Product>()
.Where(p => p.Price > 100)
.OrderByDescending(p => p.CreatedAt)
.Take(10);
// Translate to MongoDB aggregation pipeline
var mongoPipeline = query.ToMongo();
Advanced Features
Multiple Comparison Operators
var query = QueryFlow.From(typeof(Product))
.WhereIn("Category", "Electronics", "Books", "Toys")
.WhereBetween("Price", 10, 100)
.WhereLike("Name", "%phone%")
.Where("Brand", "Apple", ComparisonOperator.NotEqual);
Combining Conditions
var query = QueryFlow.From<Product>()
.Where(p => p.Category == "Electronics")
.Where(p => p.Price > 100)
.OrWhere(p => p.Featured == true);
Pagination Helpers
// Method 1: Using Skip and Take
var query = QueryFlow.From<Product>()
.Skip(20)
.Take(10);
// Method 2: Using Paginate
var query = QueryFlow.From<Product>()
.Paginate(page: 3, pageSize: 10); // Automatically calculates skip/take
API Reference
QueryBuilder<T> Methods
Where(Expression<Func<T, bool>>)
- Add a WHERE conditionWhere(bool condition, Expression<Func<T, bool>>)
- Conditional WHEREOrWhere(Expression<Func<T, bool>>)
- Add an OR conditionOrderBy<TKey>(Expression<Func<T, TKey>>)
- Order ascendingOrderByDescending<TKey>(Expression<Func<T, TKey>>)
- Order descendingSelect(params string[])
- Select specific fieldsSkip(int)
- Skip recordsTake(int)
- Limit resultsPaginate(int page, int pageSize)
- Pagination helperDistinct()
- Select distinct recordsJoin<TOther>()
- Join with another entityApplyTo(IQueryable<T>)
- Apply to LINQ queryToSql()
- Convert to SQL stringToMongo()
- Convert to MongoDB pipeline
DynamicQueryBuilder Methods
Where(string field, object value, ComparisonOperator op)
- Dynamic WHEREOrWhere(string field, object value, ComparisonOperator op)
- Dynamic ORWhereIn(string field, params object[] values)
- IN operatorWhereBetween(string field, object min, object max)
- BETWEEN operatorWhereLike(string field, string pattern)
- LIKE operatorOrderBy(string field, bool descending)
- Dynamic orderingSelect(params string[] fields)
- Select fieldsToSql()
- Convert to SQL string
Use Cases
REST API Filtering
[HttpGet]
public IActionResult GetProducts([FromQuery] ProductFilter filter)
{
var query = QueryFlow.From<Product>()
.Where(filter.MinPrice.HasValue, p => p.Price >= filter.MinPrice.Value)
.Where(!string.IsNullOrEmpty(filter.Category), p => p.Category == filter.Category)
.OrderBy(filter.SortBy ?? "Name", filter.SortDescending)
.Paginate(filter.Page, filter.PageSize);
var results = query.ApplyTo(dbContext.Products).ToList();
return Ok(results);
}
GraphQL Resolvers
public class ProductResolver
{
public IQueryable<Product> GetProducts(ProductArgs args)
{
var query = QueryFlow.From<Product>();
if (args.Where != null)
{
foreach (var condition in args.Where)
{
query.Where(condition.Field, condition.Value, condition.Operator);
}
}
if (args.OrderBy != null)
{
query.OrderBy(args.OrderBy.Field, args.OrderBy.Descending);
}
return query.ApplyTo(dbContext.Products);
}
}
Admin Panel Dynamic Grids
public class GridService
{
public GridResult<T> GetGridData<T>(GridRequest request) where T : class
{
var query = QueryFlow.From<T>();
// Apply filters
foreach (var filter in request.Filters)
{
query.Where(filter.Field, filter.Value, filter.Operator);
}
// Apply sorting
foreach (var sort in request.Sorts)
{
query.OrderBy(sort.Field, sort.Descending);
}
// Apply pagination
query.Paginate(request.Page, request.PageSize);
return new GridResult<T>
{
Data = query.ApplyTo(GetQueryable<T>()).ToList(),
TotalCount = GetTotalCount<T>(request.Filters)
};
}
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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.
-
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 | 149 | 9/2/2025 |