We help IT Professionals succeed at work.

Question about Join and LINQ

Please explain the fourth element contained in the Join?

List<Person> pr = db.Persons                    
                              .Join(db.PersonExceptions,                          
                              p => p.ID,                          
                              e => e.PersonID,                          
                              (p, e) => new { p, e })                    
                              .Where(z => z.e.CreatedOn >= fromDate)                    
                              .OrderByDescending(z => z.e.CreatedOn)                    
                              .Select(z => z.p)                    
                              .ToList();

Is this line:
(p, e) => new { p, e })                    
just creating a new table that is the product of the two other tables?

Thanks.
Comment
Watch Question

Rikin ShahMicrosoft Dynamics CRM Consultant
BRONZE EXPERT
Commented:
Create a list of p-e pairs where  
each element is an anonymous type that contains a
P's name and the name of the P that owns the e.

Hope this helps!
SILVER EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
"p" is the element from the outer IEnumerable--each item in Persons. "e" is the element from the inner IEnumerable--each item in PersonExceptions. The net effect is that wherever an element from each IEnumerable is equal to other by the appropriate keys, you get access to both elements--one in the "p" and the other in the "e".
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.