ORMQueryConstructionException: Unexpected operand '531' of in-clause expression: '[531]'

Posts   
 
    
olegl
User
Posts: 2
Joined: 05-Feb-2020
# Posted on: 05-Feb-2020 13:15:50   

Hi! .net 461, MSSQL 13.0.5081.1

We migrated from 4.1 LLBLGen to 5.6.1 RTM

following code worked in 4.1


var programIds = Enumerable.Range(1, 20).ToArray();
var activityTypeId = 1;
var templateId = 2;
var activityPrograms = CreateLinqMetaData().ActivityAttachment
    .Where(aa => aa.Activity.ActivityTypeId == activityTypeId
                          && aa.Document.TemplateId = templateId)
    .Select(aa => aa.Activity.ProgramId); 
var programExists = activityPrograms.Any(pid => programIds.Contains(pid));

but throw exception in 5.6.1

Please, help us understand why an exception is thrown. Is it bug in our code or in LLBLGen?

exception:


SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryConstructionException: Unexpected operand '531' of in-clause expression: '[531]'. Did you pass an in-memory method call to an in-memory Contains() method?
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleInClauseExpression(InClauseExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleLambdaExpression(LambdaExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAllAnyExpression(AllAnyExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at 

P.S. We have 2 working workarounds 1. Add .ToArray() to .Select(aa => aa.Activity.ProgramId) 2. move Contains to Where\Any


var programExists = CreateLinqMetaData().ActivityAttachment
    .Any(aa => aa.Activity.ActivityTypeId == activityTypeId
                          && aa.Document.TemplateId = templateId
                           && programIds.Contains(aa.Activity.ProgramId));

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Feb-2020 17:32:54   

We'll look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Feb-2020 15:38:15   

Reproduced

[Test]
public void ContainsOnListInAnyTest()
{
    var orderIds = Enumerable.Range(10254, 10270).ToArray();
    using(var adapter = new DataAccessAdapter())
    {
        var metaData = new LinqMetaData(adapter);
        var q = metaData.OrderDetail.Select(od => od.OrderId);
        var exists = q.Any(id => orderIds.Contains(id));
        Assert.IsTrue(exists);
    }
}

It gets a SetReference expression which isn't expected. I think it doesn't work anymore because, ironically enough, the Linq provider got a lot better but that meant it can now handle way more expression trees which it otherwise ignored/didn't handle properly, which in this particular case would be beneficial.

We'll see what we can do to fix this. We hope to have a fix later today, otherwise hopefully tomorrow. (altho with linq issues it might take a day longer or so)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Feb-2020 16:05:06   

We fixed it, we'll release a new hotfix build for 5.6.2 later today or tomorrow including the fix.

Frans Bouma | Lead developer LLBLGen Pro
olegl
User
Posts: 2
Joined: 05-Feb-2020
# Posted on: 07-Feb-2020 04:29:34   

Thank you very much!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Feb-2020 15:36:33   

Hotfix for this problem is now available (see My Account -> 5.5 / 5.6-> Hotfix to download the latest installer. Also on nuget (you have to select prerelease to see it in the nuget explorer)

Frans Bouma | Lead developer LLBLGen Pro