[70782 Closed] Linq

Can someone please translate this line of code into Oxygene? The oxidizer just punts. TwitterCtx is a “Twitter Context” construct from the linqToTwitter API. More code context can be seen in the first example, here: http://linqtotwitter.codeplex.com/wikipage?title=Looking%20Up%20Friendships&referringTitle=Handling%20Friendships

     var relationships =
            await
            (from look in twitterCtx.Friendship
             where look.Type == FriendshipType.Lookup &&
                   look.UserID == "15411837,16761255"
             select look.Relationships)
            .SingleOrDefaultAsync();

Presuming the right uses are in place and it’s on a 4.5 framework something like this should work:

  var relationships :=
            await
            ((from look in twitterCtx.Friendship
             where (look.Type = FriendshipType.Lookup) and 
                   (look.UserID = "15411837,16761255") 
             select look.Relationships)
            .SingleOrDefaultAsync());

The = in the first line changed to :=

Ok, thank you. I get an error now running it as async:

Error 3 (E336) “await” requires a method with no result, or one that returns a Task or Task

When I remove the await and async it works, alhtough I’d like to get it to run asynchronously.

Can you try what I changed now? (add the parenthesis)

Make sure you got the uses set and use the 4.5 framework though, else it will show that error.

Same error.

Framework 4.5.1

That’s odd. I just grabbed the 4.5 LinqTotwitterPCL.dll (from the page referenced above), copy/pasted this:

namespace ConsoleApplication89;

interface

uses
  LinqToTwitter,
  System.Linq;

type
  ConsoleApp = class
  public
    class method Main(args: array of String);
  end;

implementation

class method ConsoleApp.Main(args: array of String);
begin
  var twitterCtx: TwitterContext;
  var relationships :=
            await
            ((from look in twitterCtx.Friendship
             where (look.Type = FriendshipType.Lookup) and 
                   (look.UserID = "15411837,16761255") 
             select look.Relationships)
            .SingleOrDefaultAsync());
end;

end.

and it compiles just fine

Would there be a uses that i’m missing specifically for async?

Do you have:

uses
  LinqToTwitter,
  System.Linq;

else can you post or mail your project?

Oh, I see that it’s referring to the method that the code is contained in. The error shows in that method’s definition line in the usercontrol’s type declaration (which returns a boolean). I’m trying to figure out why it cares what the result of the method it’s wrapped in is.

Methods that use await should have a Task as a result (in your case Task then) that way the caller can wait for it.

So the method that compiles is

method uc_twitter_shared.fillRelationships:System.Threading.Tasks.Task;

how would that be called?

await uctwitter.fillRelationships

Removing the async for the moment; one thing at a time. Any idea why I get the exception: “Requires ScreenName or UserID with a comma-separated list of twitter screen names or user IDs, respectively.” when userId is obviously there?

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

More information: Inspecting the relationships.expression during runtime returned this:

{value(LinqToTwitter.TwitterQueryable`1[LinqToTwitter.Friendship]).Where(look => ((look.Type == Lookup) AndAlso op_Equality(look.UserID, “15411837,16761255”)))}

Which is C# syntax, right? I’m assuming since the dll was written in C# that this is correct, but I don’t see what is causing the error. Stumped here. This is the ONLY reason that I upgraded because I need to make this API call work as the toolset I was using before didn’t handle int64 user ID’s and is no longer being supported. Help!

Note: I cycled back to version 2 of linqToTwitter to get the async complications out of the problem but the error is the same.

It probably expects some exact thing C# does for this, even though this is actually correct. I can look into fixing it but do you have a working project that shows this so I can see it myself?

Yes, but it’s absolutely huge. I can make a smaller one that will generate the same error, but I need to email it to you because it will contain oauth keys.

that’s fine. use ck@

Done.

Thanks, logged as bugs://70782: Equals on string creates call instead of equality op