LINQ query for object with a sub-list

Asked

Viewed 29 times

-1

I have the following structure:

public class Insumo{
    public int Insumo_id { get; set; }
    public List<InsumoDados> Dados{ get; set; }
}

public class InsumoDados{
    public int Desc { get; set; }
    public decimal Valor{ get; set; }
}

I need to make an appointment at the bank so she can already return me a list of class Input. Preferably one with Lynne. Something like:

 var listInsumo = (from insumo in banco.orc_insumo                        
                    select new Insumo
                    {
                        Insumo_id = insumo.insumo_id,
                        .
                        .
                        .

Can anyone help me? Thank you.

  • You created DbSet of Insumo and InsumoDados?

  • I did create @Barbetta

  • 1

    If it works out later, I’ll give you an answer. Try it this way: var lista = seuContexto.Insumos.Include(p=> p.Dados).ToList();

1 answer

1


An alternative is to do as follows:

var listInsumo = seuContexto.Insumos.Include(p=> p.Dados).ToList(); 

Use the Include to make join, if you need to

Another way:

var listInsumo = from insumo in banco.orc_insumo                    
                select insumo;

BS: I don’t know your name DbSet then you may have to adjust the name of the properties

Browser other questions tagged

You are not signed in. Login or sign up in order to post.