Invalid operand swapping

Posts   
 
    
Posts: 12
Joined: 15-Jul-2010
# Posted on: 04-May-2012 13:56:17   

Hello,

I've a strange problem with a linq query.

When I execute the following linq queries, I got different results.

Dim queryOk = From h In metaData.THisAedPac Where h.THisAedPac_Mont.Value < 100

Dim openWrong = From h In metaData.THisAedPac Where 100 > h.THisAedPac_Mont.Value

The difference between the two queries is the position of the compare value (in this case "100").

Here the produced SQL-Query:

SELECT TOP(@p2) COUNT(*) AS [LPAV_] FROM [Test].[dbo].[THisAedPac]  [LPLA_1]   WHERE ( ( ( ( [LPLA_1].[THisAedPac_Mont] < @p3))))

SELECT TOP(@p2) COUNT(*) AS [LPAV_] FROM [Test].[dbo].[THisAedPac]  [LPLA_1]   WHERE ( ( ( ( [LPLA_1].[THisAedPac_Mont] <= @p3))))

As you see, not only the position of my constant but also the meaning of operand is swapped. ">" is converted to "<=" which is wrong!

When I execute the same queries with "Field > 100" or "100 < Field" the produced SQL-Queries are the correct. The position of the constant is swapped and "<" is converted to ">".

For me, this is a problme in the DetermineComparisonOperatorForPredicate-Function of the LinqUtils-Class. In this function the operand GreaterThan is swapped to LessEqual. Must GreaterThan not be swapped to LessThan?

I'm using LLBLGen 3.1 (release date April 14th, 2011) with VB.Net 2010.

Any help is appreciated!

With best regards,

Ingbert

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-May-2012 02:46:13   

Hi Ingbert,

You didn't provide your runtime library version (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12769), which is different from the Designer build. Anyway I think you are using an old RTL because I can't reproduce it. These are my tests:

// field > value
var products1 = (from p in metaData.Product
                    where p.UnitPrice > toCompare
                    select p).ToList();

// value < field
var products2 = (from p in metaData.Product
                    where toCompare < p.UnitPrice 
                    select p).ToList();

// test
Assert.AreEqual(products1.Count, products2.Count);


// field > value. Aggregate version
var count1 = (from p in metaData.Product
                where p.UnitPrice > toCompare
                select p).Count();

// value < field. Aggregate version
var count2 = (from p in metaData.Product
                where toCompare < p.UnitPrice
                select p).Count();
                
//test
Assert.AreEqual(count1, count2);

The generated SQL is exactly the same for the first two fetches, and the last two as well. So please update to the latest runtime library version (download the full installer and re-install).

David Elizondo | LLBLGen Support Team
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-May-2012 03:05:06   

My bad: I tested with ">" which you said worked fine. If I use "<" it indeed fails disappointed

[TestMethod]
public void LessThanGreaterThanLinqIssue()
{
            
    var toCompare = 22M;
            
    using (var adapter = new DataAccessAdapter())
    {
        var metaData = new LinqMetaData(adapter);

        // field < value
        var products1 = (from p in metaData.Product
                            where p.UnitPrice < toCompare
                            select p).ToList();

        // value > field
        var products2 = (from p in metaData.Product
                            where toCompare > p.UnitPrice 
                            select p).ToList();

        // test
        Assert.AreEqual(products1.Count, products2.Count);


        // field < value. Aggregate version
        var count1 = (from p in metaData.Product
                        where p.UnitPrice < toCompare
                        select p).Count();

        // value > field. Aggregate version
        var count2 = (from p in metaData.Product
                        where toCompare > p.UnitPrice
                        select p).Count();
                
        //test
        Assert.AreEqual(count1, count2);
    }
            
}

We are looking into this...

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 05-May-2012 11:24:31   

Our mistake, we'll fix this on monday.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 07-May-2012 11:09:27   

Fixed in attached build (v3.1)

Attachments
Filename File size Added on Approval
SD.LLBLGen.Pro.LinqSupportClasses.NET35.zip 89,570 07-May-2012 11:09.34 Approved
Frans Bouma | Lead developer LLBLGen Pro
Posts: 12
Joined: 15-Jul-2010
# Posted on: 08-May-2012 08:14:37   

Otis wrote:

Fixed in attached build (v3.1)

Thank you Frans,

I've tested the fix and everything work as expected!