Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Like keyword in Dynamic Linq

I want to use SQL's Like keyword in dynamic LINQ.

The query that I want to make is like this

select * from table_a where column_a like '%search%'

Where the column_a can be dynamically changed to other column etc

In this dynamic LINQ

var result = db.table_a.Where( a=> (a.column_a.Contains("search")) );

But the column can't be dynamically changed , only the search key can

How do we create a dynamic LINQ like

var result = db.table_a.Where("column_a == \"search\"");

That we can change the column and the search key dynamically

like image 971
strike_noir Avatar asked Jun 11 '26 02:06

strike_noir


1 Answers

This should work for you:

.Where("AColumnName.Contains(@0)", "Criteria") 
like image 175
sholdsto Avatar answered Jun 15 '26 20:06

sholdsto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!