none
Problem With Object Type After Joining 2 tables. RRS feed

  • Question

  • Hi Everyone,

    I'm new to "LINQ to SQL"... and I've been having this problem:

    I Usually do this when I try to retrieve info from the database

     

            public IQueryable<Periodos> obtenerPeriodos(int id)
            {
    
                var periodos = from periods in db.Periodos
                               where (periods.id == id) && (periods.estado == "A")
                               select periods;
    
                return periodos.AsQueryable();
            }
    

     

    However... when I try to join 2 tables I dunno what type of Object to return...

     

           public ???? obtenerArchivos(DateTime fechaActual, int estandar) 
            {
    
                var files = from archivos in db.Archivos
                             join documentos in db.Documentos on archivos.documento equals documentos.id
                             join periodos in db.Periodos on archivos.periodo equals periodos.id
                             where ((periodos.fecha_inicial >= fechaActual) && (periodos.fecha_final <= fechaActual))
                             && (documentos.estandar == estandar)
                             orderby documentos.id
                             select new { idArchivo = archivos.id, pathArchivo = archivos.path, estadoArchivo = archivos.estado, 
                                 aplicaDocumento = documentos.aplica, nombreDocumento = documentos.nombre };
    
                return ????? ;
                
            }
    


     

    I've read lots of tutorials and guides but I've couldn't find an answer....

    Thanks a lot.

     

     


    Wednesday, November 30, 2011 10:28 PM

Answers

  • Typically, you'll want to make a custom class that contains the required information, and return an instance of that.

     

    In this case, it sounds like you are getting a "Archive", so I'd make an Archive class that contains the ID, Path, etc, and return new instances of that class.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 30, 2011 10:33 PM

All replies

  • Typically, you'll want to make a custom class that contains the required information, and return an instance of that.

     

    In this case, it sounds like you are getting a "Archive", so I'd make an Archive class that contains the ID, Path, etc, and return new instances of that class.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 30, 2011 10:33 PM
  • Exactly what I Needed.... it worked very good..... 

    Thank you so much.

    Thursday, December 1, 2011 12:47 AM