Using LINQ Contains Against SqlMethods.Like

How do I replicate the following result in my LINQ query without being called in the System.data.Linq.SqlClient helper library?

Where SqlMethods.Like(e.POSITION, "%A[FGL]7%") _

I would like this query to be more purely LINQ, if possible.

+3
source share
4 answers

EDIT: based on my comments with Lette, I initially skipped the template corresponding to SqlMethods.Like support.

Your request looks like VB, so you can really use it directly as an operator , but you need to replace it with %an Asterisk *:

Where e.POSITION Like "*A[FGL]7*" _

#, Lette AsEnumerable(), (, ) .

, , 100%, SqlMethods.Like, . , .


String.Contains:
Where e.POSITION.Contains("A[FGL]7")

LINQ to SQL .NET :

  • . (...)= LIKE ...%
  • . (...)= LIKE %...%
  • . EndsWith (...)= LIKE %...
+9

: , LINQ to SQL. , .

Like SQL. , , .

:

using System.Text.RegularExpressions;

...

Regex regex = new Regex("^.*A[FGL]7.*$");

// assuming that 'e' is a sequence of elements of type Foo
IEnumerable<Foo> results = e.Where(foo => regex.IsMatch(foo.POSITION));

results .

+1

LINQ VB Like, . # Microsoft.VisualBasic.CompilerServices.LikeOperator LikeString:

using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;

...

where LikeOperator.LikeString(e.POSITION, "*A[FGL]7*", CompareMethod.Text)

, VB Like , SQL Like; * ?, % _. (LINQ to SQL VB SQL.)

( Microsoft.VisualBasic.dll.)

+1

consider something like this for membership profile information:

matches = matches.Union(memberDB.aspnet_Profile
                    .Where("it.PropertyValuesString Like @first", new ObjectParameter("first", "%<FirstName>%" + firstName + "%</FirstName>%"))
                    .Select(p => p.UserId));
0
source

Source: https://habr.com/ru/post/1730607/


All Articles