0

How to use a special (Like) Such as used in SQL?

Examples:

  1. % :Any string of zero or more characters.

  2. _ :(underscore) Any single character.

  3. [ ] :Any single character within the specified range [a-f] or set [abcdef].

  4. [^] :Any single character not within the specified range ([^a-f] or set [^abcdef].

I used manual queries with the command (SqlQuery) but I did not like, so I want a method by linq directly.

Dim Db As New HotelEntities
Dim G = (From i In Db.Profiles.SqlQuery("select * from Profile where First_Name Like '%____r'", "")).ToList

I also used the command SqlMethods.Like but did not work for me.

  • You might want to look into the [`Regex` class](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex). When using Regex, `.*` means _zero or more characters_, `.` means _any single character_, and character sets (i.e., `[ ]` and `[^]`) work exactly as you described. – 41686d6564 stands w. Palestine Apr 27 '19 at 15:11
  • Is it possible to explain my brother Ahmad by example? – Ebrahem Alabdaly Apr 27 '19 at 15:18
  • Regular Expression (Regex) is helpful in general. However, in this particular situation, it looks like you're using Entity Framework (is that correct?) If so, you won't be able to use Regex, unfortunately. You'll probably need to stick to a query or try to adopt a workaround. See [this](https://stackoverflow.com/a/3987782/4934172) and [this](https://stackoverflow.com/a/2585564/4934172). – 41686d6564 stands w. Palestine Apr 27 '19 at 15:33
  • using Entity Framework (is that correct? yes. – Ebrahem Alabdaly Apr 27 '19 at 15:41
  • 2
    Possible duplicate of [Like Operator in Entity Framework?](https://stackoverflow.com/questions/1033007/like-operator-in-entity-framework) – 41686d6564 stands w. Palestine Apr 27 '19 at 15:53

0 Answers0