Expressions with var problem

Posts   
 
    
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 11-May-2007 16:27:44   

Hi,

I'm using v2.0.0.0, 14 feb 2007, Adpater scenario. the DB is Postgres.

i want to do that :

SELECT * FROM "RSI_RepereSituation" WHERE "RSI_IdRepereSituation" & 13 = "RSI_IdRepereSituation"

replacing "13" by a var.

I'm using expressions to do that :


Dim pe As New PredicateExpression()
dim rsi as Integer = 13

Dim expRSI As New Expression(LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation, ExOp.BitwiseAnd, rsi) <-- Exception

pe.Add(New FieldCompareExpressionPredicate(LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation, Nothing, ComparisonOperator.Equal, expRSI))

Dim lignesMatchingCSP As List(Of Integer) = group.LDR_LigneDetailRepartition.FindMatches(pe)


rsi is an integer, it represents the number 13 in the SQL query. Unfortunately, this code throws an exception because rsi is not the same type than LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation.

How can I do that ? is it possible with Expressions ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-May-2007 16:50:40   

this code throws an exception because rsi is not the same type than LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation.

I think it doesn't have to be of the same type, would you please try to cast it to object.

Dim expRSI As New Expression(LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation, ExOp.BitwiseAnd, (object)rsi)
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 11-May-2007 17:02:59   

with the cast it is the same...

error message :

Left operand and right operand aren't of the same type. Left operand is of type 'System.Int32', right operand is of type 'SD.LLBLGen.Pro.ORMSupportClasses.ExpressionElement`1[System.Object]'

call stack :

à SD.LLBLGen.Pro.ORMSupportClasses.Expression.PerformGetValue(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses\Expression.cs:ligne 381 à SD.LLBLGen.Pro.ORMSupportClasses.Expression.SD.LLBLGen.Pro.ORMSupportClasses. IExpressionInterpret.GetValue(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses\Expression.cs:ligne 1325 à SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareExpressionPredicate.InterpretPredicate(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses \FieldCompareExpressionPredicate.cs:ligne 287 à SD.LLBLGen.Pro.ORMSupportClasses.Predicate.SD.LLBLGen.Pro.ORMSupportClasses. IPredicateInterpret.Interpret(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses\Predicate.cs:ligne 152 à SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.InterpretPredicate(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses\ PredicateExpression.cs:ligne 330 à SD.LLBLGen.Pro.ORMSupportClasses.Predicate.SD.LLBLGen.Pro.ORMSupportClasses. IPredicateInterpret.Interpret(IEntityCore entity) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ORMSupportClasses\Predicate.cs:ligne 152 à SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1.FindMatches(IPredicate filter) dans E:\Projets\Projets DotNet\Frameworks\LLBLGen2\RuntimeLibraries\SourceCode\Net2.x\ ORMSupportClasses\CollectionCore.cs:ligne 504 à Cogetise.Business.PlanDeCalcul.PlanDeCalculController.GeneratePlanDeCalcul(ORG_OrgaEntity orga, CSP repere, CPT_CompteEntity compteOrga, PSD_PeriodeSyndicaleEntity periode, TextWriter outStream, TextWriter errorStream) dans E:\Projets\Projets DotNet\Projets Web\cogetiseTFS\Cogetise.Business\PlanDeCalcul\PlanDeCalculController.vb:ligne 341 à Cogetise.Business.PlanDeCalcul.PlanDeCalculController.GeneratePlansDeCalcul(ORG_OrgaEntity orga, CPT_CompteEntity compteOrga, TextWriter outStream, TextWriter errorStream) dans E:\Projets\Projets DotNet\Projets Web\cogetiseTFS\Cogetise.Business\PlanDeCalcul\PlanDeCalculController.vb:ligne 285 à Cogetise.Business.PlanDeCalcul.PlanDeCalculController.GeneratePlansFromRepartition(EntityCollection1 orgas, TextWriter outStream, TextWriter errorStream) dans E:\Projets\Projets DotNet\Projets Web\cogetiseTFS\Cogetise.Business\PlanDeCalcul\PlanDeCalculController.vb:ligne 221

**update **:

i debug into LLBL sourcecode and it seems the error is with this line :

pe.Add(New FieldCompareExpressionPredicate(LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation, Nothing, ComparisonOperator.Equal, expRSI))

the left operand value (integer) is the value of LDR_LigneDetailRepartitionFields.RSI_IdRepereSituation, and right operand is expRSI.

but I don't understand why it crash...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-May-2007 17:12:33   

Strange as the following is the list of possible Expression constructor overloads.

Expression Constructor() CTor
Expression Constructor(IEntityFieldCore) Expression Constructor(IEntityFieldCore,ExOp,IEntityFieldCore) Expression Constructor(IEntityFieldCore,ExOp,IExpression) Expression Constructor(IEntityFieldCore,ExOp,Object) Expression Constructor(IExpression,ExOp,IEntityFieldCore) Expression Constructor(IExpression,ExOp,IExpression) Expression Constructor(IExpression,ExOp,Object) Expression Constructor(Object,ExOp,IEntityFieldCore) Expression Constructor(Object,ExOp,IExpression) Expression Constructor(SerializationInfo,StreamingContext)

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 11-May-2007 18:18:38   

I dugg again in the LLBLGen Pro code, and I found a wierd thing in Expression.cs line 468 :


                case ExpressionElementType.Value:
                    toReturn = operand;
                    break;


shouldn't be :


                case ExpressionElementType.Value:
                    toReturn = operand.Contents;
                    break;

I'm with the latest build.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39916
Joined: 17-Aug-2003
# Posted on: 13-May-2007 13:52:17   

Good catch, it's indeed a silly bug. I'll fix it in the next build. simple_smile

Frans Bouma | Lead developer LLBLGen Pro