0

I have two dataTable called A and B , i need all rows from A and matching row of B

A:                                           B:

User | age| Data                            ID  | age|Growth                                
1    |2   |43.5                             1   |2   |46.5
2    |3   |44.5                             1   |5   |49.5
3    |4   |45.6                             1   |6   |48.5

And the Output will be

User | age| Data |Growth
------------------------                           
1    |2   |43.5  |46.5                           
2    |3   |44.5  |                          
3    |4   |45.6  |

In this case I got a solution from StackOverflow.com Link

var results = from data in userData
              join growth in userGrowth
              on data.User equals growth.User into joined
              from j in joined.DefaultIfEmpty()
              select new 
              {
                  UserData = data,
                  UserGrowth = j
              };

It's working fine, but I am little bit confused there, What is the differences between join and joined in this LINQ Query. Thank you.

Community
  • 1
  • 1
  • 1
    `joined` is just a variable name. You could name it whatever you want to. –  Jun 29 '16 at 12:25

2 Answers2

2

joined is a variable name for the result of the join or group by operation. just to be able to use it in the from clause.

MSDN:

The into contextual keyword can be used to create a temporary identifier to store the results of a group, join or select clause into a new identifier. This identifier can itself be a generator for additional query commands. When used in a group or select clause, the use of the new identifier is sometimes referred to as a continuation.

In your case, the joined identifier is used in order to perform a LEFT JOIN. By checking if the result of join (which is stored in joined) is empty, then j would be null and the record will not be skipped (as in an INNER JOIN).

Zein Makki
  • 29,485
  • 6
  • 52
  • 63
0

joined is just the variable name of the resulting collection. You can see it gets created in the line that ends with into joined. Then it is used in the next line.

Mike
  • 5,918
  • 9
  • 57
  • 94