Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

show relational tables info in DGV using C# and EF

$
0
0

Hello there.

I'm working on C# and Entity Framework on a three tier app(DAL, BAL and GUI), but i do have a problem:

below is the model the EF created for my very simple database

what I want is to display the info related to continente and pais in a datagridview, but when I type this code in my DAL:

public List<continente> listado_dgv() { 
        using(conexxx cnn= new conexxx()){

        var listado = (cnn.continente.Include("Pais")).ToList();

 return listado;

it shows me the info in the DataGridView this way:

                  

 I don't get any information from the table pais, I googled it and created a new class called continenteExtendido like this:

 public List<continenteExtendido> listado_dgv_ext()
        {
            using (conexxx cnn = new conexxx())
            {
                var listado = cnn.continente.Include("pais")
                                .Select(x => new continenteExtendido()
                                {
                                    id_continente = x.id_continente,
                                    name_continte = x.name_continente,
                                    pais = x.pais.name_pais
                                });

                return listado.ToList();
            }
        }

but it doesn't work either, could you please help me and tell me how do I have to code my function please



pabletoreto


Viewing all articles
Browse latest Browse all 2535

Trending Articles