Like Operator

Like Operator

Postby Zero-G. » Tue 17 Aug 2010 12:54

Hey
I use your latest Components of LinQConnect for mySQL and VB.NET 2010

I use the Like Operator for dynamic queries like the following sample:

Code: Select all
Dim result As IQueryable(Of VOptNeuContext.Artikelstamm) = myDataContext.Artikelstamms

        result = result.Where(Function(Artikel) Artikel.Geloescht = 0)
If txtArtNummer.TextLength > 0 Then
            result = result.Where(Function(Artikel) Devart.Data.Linq.SqlMethods.Like(Artikel.Artikelnr, txtArtNummer.Text))
        End If
bindingSource.DataSource = result

By using the Log Property of the Context, I found out, that the following SQL is crated:
Code: Select all
SELECT t1.ID, t1.geloescht, t1.InvNr, t1.Lieferant, t1.ArtikelNr, t1.Groesse, t1.Farbe, t1.ArtBez, t1.Mwst, t1.VPreis, t1.DivArt, t1.iCode, t1.oCode, t1.oepreis, t1.EPreis, t1.DatSeit, t1.DatlAenderung, t1.kommisionsware, t1.kommisionswarezurueck, t1.gueltig_von, t1.gueltig_bis, t1.Zeitstempel
FROM artikelstamm t1
WHERE (t1.ArtikelNr LIKE :p0) AND (t1.geloescht = :p1)
-- p0: Input VarChar (Size = 2; DbType = AnsiString) [OP]
-- p1: Input Int (Size = 0; DbType = Int32) [0]
-- Context: Devart.Data.MySql.Linq.Provider.MySqlDataProvider Model: am Build: 1.0.39.0


But, I think the "Like" should be created with enclosed percent.
So, the input should be: --p0: Input VarChar (Size=4; DbType = AnsiString)[%OP%]

Or am I wrong?
Zero-G.
 
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby StanislavK » Wed 18 Aug 2010 14:30

This is the expected behaviour, the percents should be added manually. The reason is that the percent symbol can be used in any position of the LIKE pattern. For example, if percents will be implicitly added at the beginning and at the end of the condition, the "MyString%" and "%MyString" patterns would always return the same strings.

Feel free to contact us if something is unclear.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to LinqConnect (LINQ to SQL support)