0

I have 3 tables

Inventarios -> Localizacoes -> Etiquetas 

all have one to many relation from left to right

Problem is that i cannot seem to reach Etiquetas

// GET: api/Inventarios public IQueryable<Inventario> GetInventarios() { var inventarios = db.Inventarios.Include(i => i.Localizacoes.Select(l => l.Etiquetas.SelectMany(e => e.Numero))); return inventarios; } 

and here are the models

public class Inventario { public int InventarioID { get; set; } public string Colaborador { get; set; } public string Armazem { get; set; } public decimal Total { get; set; } public DateTime Data { get; set; } public ICollection<Localizacao> Localizacoes { get; set; } } public class Localizacao { public int LocalizacaoID { get; set; } public string Referencia { get; set; } public int EtiquetasPorInventariar { get; set; } public int EtiquetasInventariadas { get; set; } public bool IsValid { get; set; } public decimal Precisao { get; set; } public int InventarioID { get; set; } public Inventario Inventario { get; set; } public ICollection<Etiqueta> Etiquetas{ get; set; } } public class Etiqueta { public int EtiquetaID { get; set; } public string Numero { get; set; } public int LocalizacaoID { get; set; } public Localizacao Localizacao { get; set; } } 

this is the exception i get on browser console from api request

"The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties."

3
  • The SelectMany doesn't look right, also that fact you are returning an IQueryable is suspicious Commented Mar 16, 2019 at 23:57
  • Why so? I think it was generated from Controller class, i can't recall though Commented Mar 16, 2019 at 23:59
  • it is not clear from your question what exactly you want to get? All rows from Etiqueta? You don't have any where clause. Commented Mar 17, 2019 at 0:12

1 Answer 1

1

My assumption is you are using IQueryable for OData support

That aside, there are 2 things i am seeing here that are not looking quite right

The first, is the SelectManyit should probably be Select

var inventarios = db.Inventarios.Include(i => i.Localizacoes.Select(l => l.Etiquetas.Select(e => e.Numero))); 

The second, is you are returning IQueryable, i am not really sure this will traverse the object graph.

As a test you could do something like this

return inventarios.ToList().AsQuerable(); 
Sign up to request clarification or add additional context in comments.

1 Comment

yes it worked with select, i'm still a beginner using linq though. But either way, it's return json data in correct format and displaing in a table with 2 nested tables

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.