As mentioned in the comments above you can do this with expression trees. It will do what you need to do, but it may not be completely feasible, depending upon the size of your dataset; if you do expression trees you are doing the filtering in memory which may cause performance issues if you have large datasets.
Another option is to do the filtering in a stored procedure. Using SQL Server, for instance, you can default your parameters to NULL like this:
@Authors VARCHAR(50) = NULL, @Genre VARCHAR(50) = NULL, @BookId VARCHAR(50) = NULL, @PublishedDate VARCHAR(50) = NULL, @Title VARCHAR(50) = NULL
And then filter in your where clause:
WHERE (Authors LIKE @Authors OR @Authors IS NULL) AND (Genre LIKE @Genre OR @Genre IS NULL) AND (BookId LIKE @BookId OR @BookId IS NULL) AND (PublishedDate LIKE @PublishedDate OR @PublishedDate IS NULL) AND (Title LIKE @Title OR @Title IS NULL)
That makes for some ugly SQL, and you should probably clean up the data types, but you get the idea. Going the SQL route is not really sustainable for a large number of search parameters.
If you decide to go the expression tree route, I have a demo project I wrote for a presentation that you might be able to use as a starting point:
Hope that helps
- Web API Dynamic LINQ Search
- Creating Dynamic Search Queries with Entity Framework Web API using passed in parameters as the search fields
- Dynamic LINQ queries for a web API
- LINQ Recursive query in web api code
- Web API Controller POST Request LINQ search through String Array
- Dynamic LINQ API with .NET Framework 4
- LINQ Source Code Available
- ASP.NET search form - dynamic Linq to SQL?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- Wrong Serialization on LINQ Web API
- creating Linq to sqlite dbml from DbLinq source code
- Dynamic "Not" by parameter in LINQ (Or any other code for that matter)
- Is Dynamic LINQ still in use and suitable for narrowing-down search results?
- case insensitive dynamic search for linq to entities
- LINQ query JOIN two tables for Web API controller method
- how to create dynamic linq query based on search criterias
- How to search with dynamic entity names with linq
- Linq dynamic queries for user search screens
- Filter IEnumerable Data using Linq on ASP.NET Web API 2
- Linq to remove duplicates in ASP.NET WEB API in unconventional way
- Open source LINQ search engine for website
- Make access possible to dynamic table LINQ EF6 Code First
- LINQ to Entity Framwework Multiple Joins with Multiple Dynamic Search Criteria
- ASP.NET Web API: Perform Search on Table using HTTP GET Method and Linq to SQL Dynamically
- C# Web API LINQ Entity Queries - Cast AnonymousType to Class-Object
- How to cast my Linq query to the expected Web API return type
- source code for LINQ 101 samples
- Most efficient way to create a dynamic LINQ query that depends on multiple search fields?
- Dynamic Linq Search Expression on Navigation Properties
- LINQ time subtraction in web api
More Query from same tag
- LINQ Join return explicit type and not VAR
- Rewriting a SQL with LINQ
- Linq Intersect with partial match
- Linq Not Working on a List of Strings
- Find string in gatagrid view column
- DataBind into DB from Class in asp.net
- Querying XElement using Linq - getting XElement deep down
- Error, method not supported by LINQ to Entities
- How to return all ranges that are not included in any other range C# list
- Generic code to determine how many rows from a table are in a different table with matching structure?
- Linq calling a method in select statement very slow
- Type Member "Age" is not supported in LINQ to Entities when using ODataQueryOptions
- Add a dimension to an existing Array of Array Linq
- Can I rewrite the following code using LINQ?
- Dynamic Linq Library Help
- Expression Trees: Filtered count on navigation property
- Dictionary look up where we want the keys contained in a string
- How does OrderBy in LINQ work (behind the scenes)?
- Find the number that don't exist in another array
- How to use Expressions to invoke a method call with a generic list as the parameter?
- Do you know another way to do this "massive" linq filtering?
- Get property from object and check if it contains value
- How to create a dictionary in LINQ when populating a class?
- Group by name in MVC foreach loop to get a count
- How to pass a user-input string as a field name to access a field within an object?
- Linq Search Principle and child collection with OR statement
- Select object by literal text name in Linq
- LINQ Iterator Exception Handling
- Parsing a single-statement boolean expression tree
- Parse XML with LINQ to get child elements