I have a procedure in SQL that I am trying to turn into Linq:
SELECT O.Id, O.Name as Organization
FROM Organizations O
JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId
where OH.Hierarchy like '%/12/%'
The line I am most concerned with is:
where OH.Hierarchy like '%/12/%'
I have a column that stores the hierarchy like /1/3/12/ for example so I just use %/12/% to search for it.
My question is, what is the Linq or .NET equivalent to using the percent sign?
For those how tumble here like me looking for a way to a "SQL Like" method in LINQ, I've something that is working very good.
I'm in a case where I cannot alter the Database in any way to change the column collation. So I've to find a way in my LINQ to do it.
I'm using the helper method
SqlFunctions.PatIndex
witch act similarly to the real SQL LIKE operator.First I need enumerate all possible diacritics (a word that I just learned) in the search value to get something like:
and then in LINQ for exemple:
So for my needs I've written a Helper/Extension method
If any of you have suggestion to enhance this method, I'll be please to hear you.
Try this, this works fine for me
I do always this:
I know I don't use the like statement but it's work fine in the background is this translated into a query with a like statement.
Well indexOf works for me too
Contains is used in Linq ,Just like Like is used in SQL .
. . .
You can write your SQL script in Linq as Following :
.NET core now has
EF.Functions.Like