LINQ query for object with a sub list

-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 query the database so that it already returns a list of the Input class. Preferably with linq. Something like:

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

Can anyone help me? Thank you.

    
asked by anonymous 27.07.2018 / 23:39

1 answer

1

An alternative is to do the following:

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

Use Include to make join , if needed

Another way:

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

obs: I do not know the name of your DbSet so you might have to adjust the properties name

    
28.07.2018 / 02:27