LINQ string field compare generate the wrong SQL operator

Posts   
 
    
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 18-Nov-2010 15:39:15   

I'm approaching LINQ to LLBLGen for the first time, but I'm having an issue. I'm executing the following code

Dim metaData As New LinqMetaData(DAL.DataAdapterFactory.GetThreadDataAdapter(enDalDB.eDBDati))
Dim q = From c In metaData.Persona
Where c.Nome <> "Massimiliano"
Select c

This code should load a collection of PersonaEntity, the field PersonaEntity.Nome is a nullable string. This LINQ generate the following SQL, with a wrong where.

Query: SELECT [LPLA_1].[IDPersona] AS [Idpersona], [LPLA_1].[IDAppellativo] AS [Idappellativo], [LPLA_1].[IDTitoloOn] AS [IdtitoloOn], [LPLA_1].[Cognome], [LPLA_1].[Nome], ......
 FROM [Persona] [LPLA_1] WHERE ( ( ( ( [LPLA_1].[Nome] = @Nome1))))
    Parameter: @Nome1 : String. Length: 100. Precision: 0. Scale: 0. Direction: Input. Value: "Massimiliano".

My LINQ say: Where c.Nome <> "Massimiliano" but the generated SQL say: WHERE ( ( ( ( [LPLA_1].[Nome] = @Nome1))))

So I'm asking for a string "not equal to", but instead I get the string "equal to" the specified one. Even the LINQ "Where c.Nome >"Massimiliano"" generate a "=" in SQL

If I try the same thing on an integer field, instead, it works as it should.

I'm using the following development setting: *) LLBLGenPro 2.6 Final (09-October-2009) (Library Lib 2.6.10.0930) *) Code generation: Adapter/VB.Net 3.5/Standard Templates *) .Net 3.5, VisualStudio 2010 *) Database: Access2k

Thanks, Massimiliano

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 18-Nov-2010 17:34:31   

Does it work correctly if you use != rather than <> ?

Matt

Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 18-Nov-2010 17:44:38   

MTrinder wrote:

Does it work correctly if you use != rather than <> ?

Matt

I can't, I'm using VB.Net and "!=" doesn't compile simple_smile

The closest thing I can do is write a LINQ like "Where NOT (c.Nome = "Massimiliano")" but it doesn't work, it result in the same wrong SQL.

All the following LINQ clause generate the same SQL: LINQ: "Where NOT (c.Nome = "Massimiliano")" LINQ: "Where c.Nome <> "Massimiliano"" LINQ: "Where c.Nome = "Massimiliano""

--> SQL: "WHERE ( ( ( ( [LPLA_1].[Nome] = @Nome1))))"

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 18-Nov-2010 21:30:43   

Hmm - good point. We'll take a look.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 19-Nov-2010 09:55:26   

We'll look into it. Very strange that <> resolves into '=' as the linq provider simply looks at the expression tree....

(edit) The string compare results in a CompareString() call, which isn't converted properly. We'll look into this (it always results in an equal comparison). Workaround is: Where Not c.Nome.Equals("Massimiliano")

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 19-Nov-2010 10:30:39   

Fixed. See attached dll.

Frans Bouma | Lead developer LLBLGen Pro
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 19-Nov-2010 10:31:41   

Otis wrote:

We'll look into it. Very strange that <> resolves into '=' as the linq provider simply looks at the expression tree....

(edit) The string compare results in a CompareString() call, which isn't converted properly. We'll look into this (it always results in an equal comparison). Workaround is: Where Not c.Nome.Equals("Massimiliano")

Thanks you very much for your support.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 19-Nov-2010 10:35:33   

Max wrote:

Otis wrote:

We'll look into it. Very strange that <> resolves into '=' as the linq provider simply looks at the expression tree....

(edit) The string compare results in a CompareString() call, which isn't converted properly. We'll look into this (it always results in an equal comparison). Workaround is: Where Not c.Nome.Equals("Massimiliano")

Thanks you very much for your support.

See my previous post, for the fixed dll simple_smile

Frans Bouma | Lead developer LLBLGen Pro