[70782 Closed] Linq

bugs://70782 got closed as fixed for release Constitution Class

To get this fixed you can either use the upcoming beta (or the next release), or use this code as a temporary workaround:

uses 
  System.Linq.Expressions,
  System.Collections.Generic,
  System.Linq,
  System.Text;

type
  [System.Runtime.CompilerServices.&Extension]
  FixOpEquals = public static class
  private
  protected
  public
    [System.Runtime.CompilerServices.&Extension]
    class method FixOpEquals<T>(x: IQueryable<T>): IQueryable<T>;
  end;

  FixOpEqualsVisitor = public class(System.Linq.Expressions.ExpressionVisitor)
  private
  public
    method VisitMethodCall(node: System.Linq.Expressions.MethodCallExpression): System.Linq.Expressions.Expression; override;
  end;

implementation

method FixOpEqualsVisitor.VisitMethodCall(node: MethodCallExpression): Expression;
begin
  if (node.Method.DeclaringType = typeOf(String)) and (node.Method.Name = 'op_Equality') then
    exit Expression.Equal(node.Arguments[0], node.Arguments[1], false, node.Method);
  exit inherited VisitMethodCall(node);
end;


method FixOpEquals.FixOpEquals<T>(x: IQueryable<T>): IQueryable<T>;
begin
  exit x.Provider.CreateQuery<T>(new FixOpEqualsVisitor().Visit(x.Expression));
end;

Place this in a unit somewhere then at the end of your query add an extension call:

   var relationships :=

        (from look in twitterLinqCtx.Friendship
         where (look.Type = FriendshipType.Lookup) and 
               (look.UserID = "15411837,16761255") 
         select look.Relationships).FixOpEquals()
        .SingleOrDefault();

This rewrites the call to be valid for the twitter code.

Carlo hold off on the previous issue that I sent to you. The answer is
that the Json structure is a set and when the API translates the members
of the set into a dynamic record, they become booleans with a false
value for some reason. The actual false value is when the field is not
part of the dynamic record at all.

So a bug in the twitter lib? oke

Bug or sloppy programming, in my opinion. Did run into an Oxygene challenge trying to deal with a dynamic set (see my other post).