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?

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
phil soady
  • 11,043
  • 5
  • 50
  • 95
  • Perhaps there is a bug in the code as `Guid` is noted to have explicit support in their documentation. – user7116 May 09 '13 at 16:37

1 Answers1

6

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

"Id.Equals(@0)"
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
  • 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 pswg – phil soady May 09 '13 at 16:58
  • 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)' – Wahid Bitar Oct 30 '16 at 13:04
  • @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`. – p.s.w.g Oct 30 '16 at 14:08
  • Thank you for your fast support. I figured it out the easiest way to do it is to use `MyGuid.Value.Equals(anotherValue)` – Wahid Bitar Oct 30 '16 at 17:24