No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Cláusula Join

25/26
Recursos

Aportes 4

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Utilizando query expression

var result = from booksAfter2005 in books 
                 join booksPublishedAfter2005 in books
                 on booksAfter2005.Title equals booksPublishedAfter2005.Title
                 where booksAfter2005.PageCount >= 500 && booksPublishedAfter2005.PublishedDate.Year > 2005
                 select booksAfter2005;

Ejemplo simple con subquerys

    public IEnumerable<Book>BooksAfter2005AndPagesGreaterThan500(IEnumerable<Book> books){

        return ( from x in (from b in books where b.PublishedDate.Year>=2005 select b) join 
        y in (from book in books where book.PageCount>500 select book) on x.Title equals y.Title
        select x);   

    } ```
 public IEnumerable<Book> LibrosConMasDe500PaginasYPublicadosDespuesDel2005()
        {
            // extension method
            // return librosCollection.Where(book => book.PageCount > 500).Join(librosCollection.Where(book => book.PublishedDate.Year > 2005), book => book.Id, book => book.Id, (book1, book2) => book1);
            // query method
            return (from book in librosCollection
                    where book.PageCount > 500
                    join book2 in librosCollection
                    on book.Title equals book2.Title
                    where book2.PublishedDate.Year > 2005
                    select book);

        }

#Cláusula Join
Al igual que en SQL tenemos en Linq un operador que nos permite interceptar dos colecciones y devolver los elementos que se encuentran en ambas colecciones.