【发布时间】:2020-05-24 11:10:41
【问题描述】:
我的数据库中有以下关系,product 有几个presentaciones_prouduct,并且在我的查询中,只有当它至少有一个产品展示时,我才需要包含它们,为此目的并创建了一个布尔属性product表中的lista_precios,作为指标,内部会处理。
进行以下查询,以包含列表,但需要很长时间,而且我有几个不需要它的产品:
var producto = await _context.Producto
.Select(x => new
{
x.Id,
x.Nombre,
x.NombreSecundario,
x.MarcaId,
x.IdCategoria,
x.IdUnidad,
x.Precio,
x.PrecioCompra,
x.Codigo,
x.CantidadInicial,
x.CantidadMinima,
x.ListaPrecios,
Include------------> x.PresentacionesProducto,
x.Descripcion
})
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id== IdProducto);
现在我尝试在系统中造成最小的开销,只包括列表(如果有任何产品),这是动态的
if (producto.ListaPrecios) {}
问题:在这种情况下,如何进行最有效的咨询?仅在您拥有产品演示的情况下才包含它们
【问题讨论】:
标签: c# .net linq entity-framework-core