logo
down
shadow

Linq SqlMethods.Like fails


Linq SqlMethods.Like fails

By : behnamy01
Date : January 02 2021, 06:48 AM
To fix this issue I don't know how you can make Entity Framework use the "real" LIKE operator, but a possible workaround would be to express a LIKE expression in terms of StartsWith, Contains and EndsWith
For instance :
code :


Share : facebook icon twitter icon
Using LINQ Contains versus SqlMethods.Like

Using LINQ Contains versus SqlMethods.Like


By : user1724599
Date : March 29 2020, 07:55 AM
Hope that helps EDIT: based on my comments with Lette I initially missed the pattern matching which SqlMethods.Like supports.
Your query looks like VB so you can actually use the Like operator directly but you'll need to replace the % with an asterisk *:
code :
Where e.POSITION Like "*A[FGL]7*" _
Where e.POSITION.Contains("A[FGL]7")
LINQ - OR two SqlMethods.Like clauses

LINQ - OR two SqlMethods.Like clauses


By : Adam jibril
Date : March 29 2020, 07:55 AM
it fixes the issue It's not clear to me why this is "obviously" not correct. Presumably it's not working, otherwise you wouldn't have posted, but it's not obvious how it's not working.
I would suggest performing the replacement before the query, like this:
code :
string vendorPattern = inputVendor.Replace("*", "%");
results = results.Where(p => SqlMethods.Like(p.VendorId, vendorPattern) ||
                             SqlMethods.Like(p.VendorName, vendorPattern));
Using LINQ with wildcard characters without using SqlMethods

Using LINQ with wildcard characters without using SqlMethods


By : M. YAZAR
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Linq is able to expand methods of System.String class like Contains into appropriate SQL queries so, the following query:
code :
var data = dataContext.Clients.Where(c => c.Name.Contains("John"));
DECLARE @p0 VarChar(1000) = '%John%'
SELECT [t0].[Id], [t0].[Name]
FROM [Clients] as [t0]
WHERE [t0].[Name] LIKE @p0
Linq SqlMethods NOT Like

Linq SqlMethods NOT Like


By : Anuj Dixit
Date : March 29 2020, 07:55 AM
should help you out I want all the fields witch dont start with 3 numbers. With the following code I get all the lines that start with a number, I want to have the inverted result. , Use this:
code :
var LEResult = (from t1 in dtClone.AsEnumerable() //TWT
                select t1).Where(q => !SqlMethods.Like(q["BillingPeriod"].ToString(), "%[0-9][0-9][0-9]"));
LINQ SqlMethods.Like (and .Contains) fails

LINQ SqlMethods.Like (and .Contains) fails


By : conan.ak
Date : March 29 2020, 07:55 AM
I wish this help you Change your Person class to include a PersonId and pass that through like oNewPerson = New Person(1, "Scarlett", "Johansson").
Change the oPeople to be a List(Of Person) so when adding it would look like this oPeople.Add(oNewPerson).
code :
Dim queryResults = From person In oPeople
                   Where person.FirstName.ToLower Like "*" & sSearchTerm & "*" Or
                         person.LastName.ToLower Like "*" & sSearchTerm & "*"
For Each result In queryResults

    If Not String.IsNullOrEmpty(result.MiddleName) Then

        Console.WriteLine(result.PersonId.ToString.PadLeft(2, CChar("0")) & ": " & result.FirstName & " " & result.MiddleName & " " & result.LastName)

    Else

        Console.WriteLine(result.PersonId.ToString.PadLeft(2, CChar("0")) & ": " & result.FirstName & " " & result.LastName)

    End If

Next
shadow
Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk