---
title: "Dynamic LINQ where query"  
description: "Dynamic LINQ where query"  
author: "Anonymous User"  
published: 2014-08-22  
updated: 2019-04-08  
canonical: https://www.mindstick.com/forum/2076/dynamic-linq-where-query  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Dynamic LINQ where query

I'm using [dynamic](https://www.mindstick.com/blog/11080/features-of-java-dynamic-complied-and-interpreted) LINQ to create a query from given columns the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) selects for a given search.

var [counter](https://www.mindstick.com/interview/33859/how-to-create-pixel-counter-in-javascipt) = 0;

var predicate = string.Empty;

[foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally)(var [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) in selectedFields)

{

predicate += field + ".Contains(@" + counter + ") ||";

// [logical](https://www.mindstick.com/forum/33581/what-is-inserted-deleted-logical-table-in-sql-server) OR, without it the SQL generates AND

}

predicate = predicate.Remove(predicate.LastIndexOf("||", 2));

query = query.Where(predicate, searchvalues);

This code generates the given [SQL query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query)

(([t0].[Field1] LIKE 'searchstring') OR ([t0].[Field2] LIKE 'searchstring'))

Which is correct, albeit what i want to do is be able to use wildcards, when i try to enter let's say, a percent [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character), the SQL generated is

(([t0].[field1] LIKE 'searchstring' [ESCAPE](https://answers.mindstick.com/qa/98969/jungle-run-temple-escape-is-better-than-temple-run) '~') OR ([t0].[field2] LIKE 'searchstring' ESCAPE '~'))

Is there a way to use wildcards in the searchstring while using dynamic L2S?

## Replies

### Reply by Anonymous User

nice article click to use dynamic SQL [Query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver)

\

### Reply by Sumit Kesarwani

Hi Goti, \

You can try using .StartsWith || .EndsWith || .Contains


---

Original Source: https://www.mindstick.com/forum/2076/dynamic-linq-where-query

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
