OrmLite/MySql/SqlExpressionVisitor - need "like" clause
Asked Answered
E

1

7

I am new to LINQ and OrmLite/MySql. I have a service request argument that needs to result in a where clause:

`Name` LIKE '%something%' OR `Name` LIKE '%something%else%'

I know I can create an IN() or an = clause, via:

ev.Where(rn => Sql.In(rn.Name, request.Name));  // Assuming an array here
ev.Where(rn => rn.Name== request.Name));

But I can't seem to find a construct that lets me build up a LIKE. Also, Name is actually an alias so I am trying to avoid constructing the where clause manually.

Electrophone answered 16/10, 2012 at 19:8 Comment(0)
B
3

You can build that particular example using Contains, i.e:

ev.Where(rn => rn.Contains(rn.Name, "something") 
    || rn.Contains(rn.Name, "something%else"));

StartsWith and EndsWith are generally used in LINQ to generate LIKE clauses with a wildcard at only one end (but it does appear the MySql dialect defines StartsWith somewhat differently, likely for efficiency.)

You can check the default dialect source code to confirm what gets generated for EndsWith and Contains.

Bovid answered 20/10, 2012 at 2:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.