Question about Join and LINQ

Posted on 2012-08-16
Last Modified: 2012-08-19
Please explain the fourth element contained in the Join?

List<Person> pr = db.Persons                    
                              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)                    

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

Question by:newbieweb
    LVL 19

    Assisted Solution

    by:Rikin Shah
    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!
    LVL 74

    Accepted Solution

    "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".

    Author Closing Comment


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now