Joining in Linq queries

Aug 2, 2010 at 3:00 PM
Edited Aug 2, 2010 at 3:01 PM

Any chance of supporting joins in the Linq queries?

This trivial (and useless) join sample blows up:

        private static void StatusCountDemo(TwitterContext twitterCtx)
        {
            var tweets =
                from tweet in twitterCtx.Status
                join tweet2 in twitterCtx.Status on tweet.ScreenName equals tweet2.ScreenName
                where tweet.Type == StatusType.Friends
                select new { tweet, tweet2 };

            var tweetCount = tweets.Count();

            foreach (var l in tweets)
            {
                Console.WriteLine(l.tweet.ScreenName);
            }
        }
 

{"Expression of type 'System.Linq.EnumerableQuery`1[<>f__AnonymousType0`2[LinqToTwitter.Status,LinqToTwitter.Status]]' cannot be used for parameter of type 'System.Linq.IQueryable`1[LinqToTwitter.Status]' of method 'System.Linq.IQueryable`1[<>f__AnonymousType0`2[LinqToTwitter.Status,LinqToTwitter.Status]] Join[Status,Status,String,<>f__AnonymousType0`2](System.Linq.IQueryable`1[LinqToTwitter.Status], System.Collections.Generic.IEnumerable`1[LinqToTwitter.Status], System.Linq.Expressions.Expression`1[System.Func`2[LinqToTwitter.Status,System.String]], System.Linq.Expressions.Expression`1[System.Func`2[LinqToTwitter.Status,System.String]], System.Linq.Expressions.Expression`1[System.Func`3[LinqToTwitter.Status,LinqToTwitter.Status,<>f__AnonymousType0`2[LinqToTwitter.Status,LinqToTwitter.Status]]])'"}

 

at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)   at LinqToTwitter.TwitterQueryProvider.Execute[TResult](Expression expression) in C:\Work\AzureStore\LinqToTwitter 2.0.11\LinqToTwitter\LinqToTwitter\TwitterQueryProvider.cs:line 110  
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)   at LinqToTwitterDemo.StatusDemos.StatusCountDemo(TwitterContext twitterCtx) in C:\Work\AzureStore\LinqToTwitter 2.0.11\LinqToTwitterDemo\StatusDemos.cs:line 607  
at LinqToTwitterDemo.StatusDemos.Run(TwitterContext twitterCtx) in C:\Work\AzureStore\LinqToTwitter 2.0.11\LinqToTwitterDemo\StatusDemos.cs:line 48  
at LinqToTwitterDemo.Program.Main(String[] args) in C:\Work\AzureStore\LinqToTwitter 2.0.11\LinqToTwitterDemo\Program.cs:line 93  
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)  
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)  
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()  
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)  
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Threading.ThreadHelper.ThreadStart()

Coordinator
Sep 11, 2010 at 9:23 PM

Hi,

You can work around this by doing two LINQ to Twitter queries and then doing a LINQ to Objects join on the result.  In the meantime, I'll mark it as an issue.

Joe

Coordinator
Sep 11, 2010 at 9:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.