0

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 ?

zey
  • 5,939
  • 14
  • 56
  • 110

2 Answers2

1

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).

Crowcoder
  • 11,250
  • 3
  • 36
  • 45
0

How about building it this way?

Where(t=>t.name.toLower() == value)
Jonny
  • 1,037
  • 7
  • 15