GenericFilterBuilder 1.0.0

dotnet add package GenericFilterBuilder --version 1.0.0                
NuGet\Install-Package GenericFilterBuilder -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="GenericFilterBuilder" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericFilterBuilder --version 1.0.0                
#r "nuget: GenericFilterBuilder, 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.
// Install GenericFilterBuilder as a Cake Addin
#addin nuget:?package=GenericFilterBuilder&version=1.0.0

// Install GenericFilterBuilder as a Cake Tool
#tool nuget:?package=GenericFilterBuilder&version=1.0.0                

Welcome to Generic-Filter-Builder!

Hi! This is my first Nuget package. I think you will find it pretty useful when creating dynamically generated filters.

GenericFilterBuilder is a generic filter builder class. Each YourDomainClass can be filtered by its properties if they are provided within filterValue.

FilterValue param is an array of FilterValueItem class serialized to Json into string.

Disclaimer: These examples are only intended to provide you enough information on how to use GenericFilterBuilder functionality

WebAPI - Example

Have in your WebApi controller or BLL service layer something like this one:

public async Task<YourDomainClassDto> GetYourWebApiUrlMethodName(string filterValue = "", string sortBy = "", OrderDirection orderDirection = OrderDirection.Desc,
	int pageNumber = 0, int pageSize = 10)
		// this is where we build our generic filter class
		var filter = new GenericFilterBuilder<YourDomainClass>()
	/// IGenericRepository interface is also provided so you can implement it within your Repository classs
	var filteredData = await this.UnitOfWork.YourDomainClassRepository.GetAllPagedAndFilteredAsync(filter, pageNumber, pageSize, sortBy, orderDirection);

	// only for demo purpose 

	return filteredData;

Repository - example

In this example, some custom wrapper SqlDapper was used, so you can ignore that part. Main goal here is to send dynamically built filter to Queryable WHERE()

        public async Task<IReadOnlyList<YourDomainClass>> GetAllPagedAndFilteredAsync(Func<YourDomainClass, bool> filter = null, int? page = null, int? recordsPerPage = null, string orderBy = null, OrderDirection orderDirection = OrderDirection.Desc)
			var dbData = await QueryDapperHelper.QueryAsync(...); // only for demo purpose
            if (filter != null)
                dbData = dbData.AsQueryable().Where(filter); // i.e.: if EF used: dbSet.Where(filter)

            if (!string.IsNullOrEmpty(orderBy))
                dbData = dbData.AsQueryable().StringOrderBy(orderBy, orderDirection);

            if (page.HasValue && recordsPerPage.HasValue)
                dbData = dbData.Skip(page.Value * recordsPerPage.Value).Take(recordsPerPage.Value);

            return dbData.ToList<YourDomainClass>();

Hopefully this is clear enough. If any questions, send me an email. Cheers.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp1.0 is compatible.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 302 2/26/2021