Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool>
Asked Answered
S

1

6

I'm Using Dynamic Linq library and there is Source code and basic docu and the Nuget version

PM> Install-Package DynamicLINQ

I'm trying to construct a where clause that involves Guids

I have tried with the string "Id == @0". The parameter array is just an object[] with the value (Guid xxxx)

  var whereClauseSB = BuildLogicalKeyWhereClause2(entity, logicalKey);  //build string
  var parms = BuildParamArray(entity, logicalKey); // object[]
  var whereLambda = Ofsi.Bos.Core.DynamicExpression.ParseLambda<T, bool>(whereClauseSB.ToString(),parms);  //parse

an exception is thrown in DynamicExpression.ParseLambda

Operator '==' incompatible with operand types 'Guid' and 'Guid'

  • I have also tried with GUID and String.(fail)
  • I tried with and "Id = @0" (fail).
  • String == string works, as does Int32==int32 but not Guid == Guid does not

Any ideas?

Semitic answered 9/5, 2013 at 16:33 Comment(1)
Perhaps there is a bug in the code as Guid is noted to have explicit support in their documentation.Render
P
7

Try using the Equals method instead of the == operator in your string:

"Id.Equals(@0)"
Phenanthrene answered 9/5, 2013 at 16:37 Comment(4)
ObjectDirectoryId.Equals(@0) && ObjectId == @1 && CultureName == @2 with the matching object[] just got parsed. :-) I will mark as correct answer once the test is complete but it looks good . Thanks pswgSemitic
It's very good but I had a problem with Nullable Guid. I got this exception Expression of type 'System.Guid' cannot be used for parameter of type 'System.Object' of method 'Boolean Equals(System.Object)'Preamplifier
@WahidBitar I'm guessing you have MyGuid.Equals(null) or MyGuid.Equals(@0) and you're passing a parameter of null fo @0. In either case, make sure the you're using in is (Guid?)null or default(Guid?) instead of just null.Phenanthrene
Thank you for your fast support. I figured it out the easiest way to do it is to use MyGuid.Value.Equals(anotherValue)Preamplifier

© 2022 - 2024 — McMap. All rights reserved.