How to join two different lists using LINQ and where?

1

I have three classes:

class Cid
{
        public string cid  { get; set; } //importo esse campo via txt
        public string descricao { get; set; } //importo esse campo via txt
}

class Relacionamento
{
        public string cid { get; set; } //importo esse campo via txt
        public string codigo { get; set; } //importo esse campo via txt
        public string procedimento { get; set; } //PRECISO DESSE CAMPO
}

class Procedimento
{
        public string codigo { get; set; } //importo esse campo via txt
        public string procedimento { get; set; } //importo esse campo via txt
}

I created a list for classes: listaCid for classe Cid , and listaProcedimento for classe Procedimento

After the created classes, the user clicks on an item of listaCid .

After clicking, listaRelacionamento is filtered using where Cid.cid = Relacionamento.Cid . So far so good.

I want to know how to include in the listaRelacionamento (after the filter), the Relacionamento.procedimento field coming from listaProcedimento

By the image, you can see: The user clicks on the grid above that receives the listCid (in this case, received the code A013) and passes the grid from the bottom listRelacionamento (see that filters all fields where cid = A013), but the third column is empty.

I want to fill the third column of the listRelationship with the blue painted field (procedure)

    
asked by anonymous 19.01.2017 / 15:51

1 answer

1

I think that if I understood your question correctly, what you want is this:

 List<Relacionamento> result = (from relacionamento in ListaRelacionamentos
                    join procedimento in ListaProcedimento
                         on relacionamento.codigo equals procedimento.codigo
                    select new Relacionamento()
                    {
                     cid =   relacionamento.cid,
                      codigo =  relacionamento.codigo,
                       procedimento = procedimento.procedimento
                    }).ToList();

But I recommend using entity framework and objects ... for example, you would only have to navigate within the object when you make the filter.

 class Relacionamento
 {
     public string cid { get; set; } //importo esse campo via txt
    public Procedimentos procedimento { get; set; } //importo esse campo via txt
}
    
19.01.2017 / 16:09