Results 1 to 4 of 4

Thread: [RESOLVED] LINQ is Missing Something, Or I Am

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Resolved [RESOLVED] LINQ is Missing Something, Or I Am

    There is this example from MS documentation:

    Code:
    Dim queryResults = From cust In customers
                       Group Join ord In orders On
                         cust.CustomerID Equals ord.CustomerID
                         Into CustomerOrders = Group,
                              OrderTotal = Sum(ord.Amount)
                       Select cust.CompanyName, cust.CustomerID,
                              CustomerOrders, OrderTotal
    A simple little example, but for me, the Into keyword is always an error. I have tried a very simple example such as this:

    Code:
                    Dim store1 As IEnumerable(Of Guid)
    		Dim store2 As IEnumerable(Of Guid)
    
    		Dim res=From gd In store1 Join gd2 In store2 On gd Equals gd2 into
    which is as simple as possible, but 'into' is underlined with the error End of Statement Expected. Normally, this means that I overlooked something, but I sure can't see what it would be.

    What am I missing?
    My usual boring signature: Nothing

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: LINQ is Missing Something, Or I Am

    The example is using Group Join while you're just using Join. I've never used Group Join but I assume that Into is specific to that.

  3. #3

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: LINQ is Missing Something, Or I Am

    Well, that's interesting, as it appears to be the case. I had tried both join and group join before I stripped it down to that simplified example, and into caused the same error both times, but now that I think about it, I never did try it with JUST a Group Join.

    When I change the example to Group Join, the error goes away. Into becomes valid and accepted. What I was doing before I stripped down the example was to join two datatables followed by a Group Join of a further datatable with the intent of doing what amounted to a Left Outer Join on that third table. Into is not allowed if there is a Join, but is allowed if there is not.

    My mental model was that Into was essentially creating a temporary table, in which case it shouldn't matter whether there was a join or group join, but that is not the case, so my mental model must be wrong. I guess I don't understand what "into" is doing.
    My usual boring signature: Nothing

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: LINQ is Missing Something, Or I Am

    As per documentation, the Into Clause applies to aggregate functions or groupings to apply to a collection which is used in Aggregate, Group By and Group Join clauses (the example that you provided).

    Edit: The C# docs has a better explanation of how into works.
    Last edited by KGComputers; Aug 27th, 2021 at 12:38 PM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width