From f5034779ae6aa350ed7e33b4977adba87654e681 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Mon, 22 Oct 2018 19:44:27 -0500 Subject: [PATCH] query result --- DynamicQuery.sln | 12 ++- PoweredSoft.DynamicQuery.Cli/Program.cs | 2 + README.md | 107 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/DynamicQuery.sln b/DynamicQuery.sln index a03a225..b51facc 100644 --- a/DynamicQuery.sln +++ b/DynamicQuery.sln @@ -3,14 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28010.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicQuery.Core", "PoweredSoft.DynamicQuery.Core\PoweredSoft.DynamicQuery.Core.csproj", "{E614658D-6852-4405-B5BE-3695C3E96B13}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicQuery.Core", "PoweredSoft.DynamicQuery.Core\PoweredSoft.DynamicQuery.Core.csproj", "{E614658D-6852-4405-B5BE-3695C3E96B13}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicQuery", "PoweredSoft.DynamicQuery\PoweredSoft.DynamicQuery.csproj", "{A9F74387-6B09-423A-96BC-F8FF345193EE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicQuery", "PoweredSoft.DynamicQuery\PoweredSoft.DynamicQuery.csproj", "{A9F74387-6B09-423A-96BC-F8FF345193EE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicQuery.Cli", "PoweredSoft.DynamicQuery.Cli\PoweredSoft.DynamicQuery.Cli.csproj", "{7FC0F790-A8B9-4335-8D72-09797DEB0359}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicQuery.Cli", "PoweredSoft.DynamicQuery.Cli\PoweredSoft.DynamicQuery.Cli.csproj", "{7FC0F790-A8B9-4335-8D72-09797DEB0359}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicLinq", "..\DynamicLinq\PoweredSoft.DynamicLinq\PoweredSoft.DynamicLinq.csproj", "{E4E954E0-66FA-4D72-979A-FB2EF8356A90}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BD742C81-D26A-466C-AB9B-840996D59FA6}" + ProjectSection(SolutionItems) = preProject + LICENSE.md = LICENSE.md + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/PoweredSoft.DynamicQuery.Cli/Program.cs b/PoweredSoft.DynamicQuery.Cli/Program.cs index 5a939c6..f2a4694 100644 --- a/PoweredSoft.DynamicQuery.Cli/Program.cs +++ b/PoweredSoft.DynamicQuery.Cli/Program.cs @@ -113,6 +113,8 @@ namespace PoweredSoft.DynamicQuery.Cli //, new Group { Path = "Sexe" } }; + + criteria.Aggregates = new List() { new Aggregate { Type = AggregateType.Count }, diff --git a/README.md b/README.md new file mode 100644 index 0000000..8747d81 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ +# Dynamic Query + +It's a library that allows you to easily query a queryable using a criteria object. + +It allows offers, to intercept the query using **IQueryInterceptor** implementations. + +## Getting Started + +> Install nuget package to your awesome project. + +Full Version | NuGet | NuGet Install +------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------: +PoweredSoft.DynamicQuery | [![NuGet](https://img.shields.io/nuget/v/PoweredSoft.DynamicQuery.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.DynamicQuery/) | ```PM> Install-Package PoweredSoft.DynamicQuery``` +PoweredSoft.DynamicQuery.Core | [![NuGet](https://img.shields.io/nuget/v/PoweredSoft.DynamicQuery.Core.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.DynamicQuery.Core/) | ```PM> Install-Package PoweredSoft.DynamicQuery.Core``` + +## Criteria + +Criteria must implement the following interfaces + +Object | Interface | Implementation | Example | Description +---------------|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------|-------------------------------------------------------------|--------------------------------------- +Query Criteria | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IQueryCriteria.cs) | [default implemetation](../blob/master/PoweredSoft.DynamicQuery.QueryCriteria.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Wraps the query parameters +Filter | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IFilter.cs) | [default implemetation](../blob/master/PoweredSoft.DynamicQuery.Filter.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a filter to be executed +Sort | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/ISort.cs) | [default implemetation](../blob/master/PoweredSoft.DynamicQuery.Sort.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a sort to be executed +Group | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IGroup.cs) | [default implemetation](../blob/master/PoweredSoft.DynamicQuery.Group.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a group to be executed +Aggregate | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IAggregate.cs) | [default implemetation](../blob/master/PoweredSoft.DynamicQuery.Aggregate.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent an aggregate to be executed + +### Sample + +```csharp +var criteria = new QueryCriteria +{ + Page = 1, + PageSize = 12, + Filters = new List + { + new SimpleFilter { Path = "FirstName", Type = FilterType.Equal, Value = "John" } + } +}; + +var queryHandler = new QueryHandler(); +IQueryExecutionResult result = queryHandler.Execute(someQueryable, criteria); +``` + +## Query Result + +Here is the interfaces that represent the result of query handling execution. + +```csharp +public interface IAggregateResult +{ + string Path { get; set; } + AggregateType Type { get; set; } + object Value { get; set; } +} + +public interface IQueryResult +{ + List Aggregates { get; } + List Data { get; } +} + +public interface IGroupQueryResult : IQueryResult +{ + string GroupPath { get; set; } + object GroupValue { get; set; } +} + +public interface IQueryExecutionResult : IQueryResult +{ + long TotalRecords { get; set; } + long? NumberOfPages { get; set; } +} +``` + + +## Interceptors + +Interceptors are meant to add hooks at certain part of the query handling to allow alteration of the criterias or the queryable it self.\ +The following is documented in the order of what they are called by the **default** query handler implementation. + +> Before the expression is being built + +Interceptor | Interface | Example | Description +---------------------------------------|--------------------------------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------------------ +IIncludeStrategyInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IIncludeStrategyInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is to allow you to specify include paths for the queryable +IIncludeStrategyInterceptor<T> | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IIncludeStrategyInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is to allow you to specify include paths for the queryable +IBeforeQueryFilterInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Before adding the filters to the expression +IBeforeQueryFilterInterceptor<T> | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IBeforeQueryFilterInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | Before adding the filters to the expression +INoSortInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 +INoSortInterceptor<T> | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/INoSortInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This is called to allow you to specify an OrderBy in case none is specified, to avoid paging crash with EF6 + +> After/During expression building before query execution + +Interceptor | Interface | Example | Description +----------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------- +IFilterInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IFilterInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a IFilter being applied to the queryable +ISortInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/ISortInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a ISort being applied to the queryable +IGroupInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IGroupInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a IGroup being applied to the queryable +IAggregateInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IAggregateInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to change the behavior of a IAggregate being applied to the queryable + +> Post Query execution + +Interceptor | Interface | Example | Description +----------------------------------|---------------------------------------------------------------------------------------|-------------------------------------------------------------|------------------------------------------------------------------------------------------------ +IQueryConvertInterceptor | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to replace the object that is being returned by the query, by another object instance +IQueryConvertInterceptor<T> | [interface](../blob/master/PoweredSoft.DynamicQuery.Core/IQueryConvertInterceptor.cs) | [test](../blob/master/PoweredSoft.DynamicQuery.Test/TBT.md) | This interceptor allows you to replace the object that is being returned by the query, by another object instance