My issue is simple but I cannot solve this and I have searched over the internet but one of them matches my issue. This is my code:
public Producto VerificarExTalla(int id, bool related = true)
{
var productos = _context.Productos.AsQueryable();
if (related)
{
productos = productos
.Include(s => s.Categoria)
.Include(s => s.DetalleTallas)
.Include(s => s.DetalleTallas.Select(a => a.Talla));
}
return productos
.Where(s => s.Id == id)
.SingleOrDefault();
}
I am trying to perform a condition after .Select()
. This is what I have tried but did not work:
.Include(s => s.DetalleTallas.Select(a => a.Talla).Where(a => a.EstadoTallaa == false));
And also tried this, inside .Select:
.Include(s => s.DetalleTallas.Select(a => a.Talla.EstadoTallaa == false));
both gives me the same error:
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. Parameter name: path'
Looking at your code it appears that you want to achieve following -
As a simple logical programmer I would like to write as follows -
productos = productos.Where(p=> p.Id == id)
.Include(s => s.Categoria)
.Include(s => s.DetalleTallas.Where(d=> d.EstadoTallaa == false));
But sadly it would not work! It will display error "Lambda expression used inside Include is not valid".
So this can be rewritten as like this -
productos = productos.Where(p=> p.Id == id)
.Select(p => new Productos
{
Id = p.Id,
Categoria = p.Categoria
// some other properties of Productos
DetalleTallas = p.DetalleTallas.Where(d => d.EstadoTallaa == false).ToList()
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加