query in Linq to entities leftjoin with an extra field

2

Good, I need to obtain the objects that are in a collection that if they exist in another, a field says "exists", and if they do not exist, say "it does not exist"

The ProgramasLivianos object has a field that is called TienePrograma . I would be interested if you can load in that field if you have or not. This object "light programs" I have it in a list called "ListResult"

Example:

ListaProgramas=  {nombre, codSiu, stream, .....} -> muchos campos extras

ListaProgramasAlumno = {nombrePrograma, AñoAprobado, plan} -> datos del legajo

ListaResultado = {nombrePrograma, TienePrograma} -> esto deberia salir de la consulta que busco, donde el campo TienePrograma deberia ser devuelto de la consulta 

It happens that sometimes the student has programs that are not yet loaded, so I would like to make a query that returns me nombreDelPrograma (extracted from the file) and if that program does not exist in the listaProgramas that the field TienePrograma be loaded with "NO"

Code that I tried:

Dim r As List(Of programas_ft_V)
r = db.ProgramaFileTable_VSet.Where(Function(x) x.unc_path.Contains("\programas_ft\programasSubidosWeb\") AndAlso
                                                                                        x.is_archive).ToList
Dim listaDT As New List(Of ProgramasLivianos) '= dataTable.AsEnumerable.ToList()
listaDT = ProgramasLivianos.CrearLista(dataTable)
Dim resultadoI = From l In r, p In listaDT
                    Where l.name.Contains(p.codSiu)
                    Select New ProgramasLivianos  With {  p.codSiu, p.nombre, p.nombre_Reducido, p.plan, p.tieneTaller, p.tienePrograma = "NoTienePrograma"}
    
asked by NioDeTark 05.07.2017 в 15:36
source

1 answer

0

According to what you comment you need to make a left join. Here is a reference on how to do a left join via linq

I give you a basic example of how it could be in your case (modify the fields you need):

 var resultadoI  = from l In ListaProgramas
    join p in ListaProgramasAlumno on p.nombrePrograma.Contains(l.codSiu) into lp
    from p in lp.DefaultIfEmpty()
    select new { nombrePrograma = p.nombrePrograma, TienePrograma = p == null ? "(NO)" : p.nombrePrograma};
    
answered by 26.03.2018 в 13:30