LOWER and REPLACE doesn't work on dynamic linq where statement

c# dynamic-linq lowercase replace sql-server-2008-r2

Question

Here is my code ,

db.myDBContext.my_tables.Where("REPLACE(LOWER(name),\" \",\"\") == \"{0}\"", value);

it show the error

No applicable method 'LOWER' exists in type 'my_table'  

can't I use REPLACE and LOWER in dynamic linq clause ?

1
0
7/5/2016 11:34:04 AM

Accepted Answer

Dynamic Linq doesn't understand T-SQL. You will want to craft it this way:

.Where(string.Format("(name).ToLower().Replace(\" \", \"\") == \"{0}\" ", value))

There is an analog for ToLower and Replace in T-SQL and Linq knows how to translate them from c#. But if name is a static column name then @Jonny is on to something. You don't need Dynamic Linq here (unless this is just a contrived example of a bigger problem you are solving).

1
7/5/2016 12:59:53 PM

Popular Answer

How about building it this way?

Where(t=>t.name.toLower() == value)


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow