Код: Выделить всё
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync
Я пытаюсь написать запрос для получения некоторых сведений о заказе вместе с их продуктами (которые имеют цвет, размер и т. д.). ). Я использую проекцию, но мне нужно получить доступ к некоторым глубоко вложенным свойствам, чтобы получить цену за измерение.
ОБНОВЛЕНИЕ: здесь я получаю все данные из таблицы соединения
Код: Выделить всё
var allProductsWithDimensions = await productsOnDimensionsRepository.GetAllAsync();
Код: Выделить всё
var allProductsOnCurrentOrder = await productsOnOrdersRepository
.FindQueryable(pc => pc.IdComanda == order.IdComandaDto)
.Select(pc => new ProductsOnOrdersDto
{
IdProdusDto = pc.Produs.IdProdus,
CodProdusDto = pc.Produs.CodProdus,
NumeProdusDto = pc.Produs.NumeProdus!,
PretBazaProdusDto = pc.Produs.PretDeBaza,
NumeProducatorDto = pc.Produs.Producator == null ? null : pc.Produs.Producator.NumeProducator,
TipulProdusuluiDto = pc.Produs.TipulProdusului,
NumeSetDto = pc.Set == null ? null : pc.Set.NumeSet,
PretSetDto = pc.Set == null ? null : pc.Set.PretSet,
PretRedusSetDto = pc.Set == null ? null : pc.Set.PretRedusSet,
NumeCuloareDto = pc.PcCuloare.NumeCuloare,
CodCuloareDto = pc.PcCuloare.CodCuloare.CodCuloare!,
LungimeDto = pc.PcDimensiune == null ? null : pc.PcDimensiune.Lungime,
LatimeDto = pc.PcDimensiune == null ? null : pc.PcDimensiune.Latime,
RecomandarePatDto = pc.PcDimensiune == null ? null : pc.PcDimensiune.RecomandarePat,
PretDto = pc.PcDimensiune == null
? null
: (from pcd in allProductsWithDimensions
where pcd.IdProdus == pc.Produs.IdProdus && pcd.IdDimensiune == pc.PcDimensiune.IdDimensiune
select pcd.Pret).First(),
PretRedusDto = pc.PcDimensiune == null
? null
: (from pcd in allProductsWithDimensions
where pcd.IdProdus == pc.Produs.IdProdus && pcd.IdDimensiune == pc.PcDimensiune.IdDimensiune
select pcd.PretRedus).First(),
PerdeaEstePerecheDto = pc.PcDimensiune == null ? null : pc.PcDimensiune.PerdeaEstePereche,
TipGalerieCusaturaDto =
pc.PcManopera == null ? null : pc.PcManopera.TipGalerieLaManopera.NumeTipGalerie,
PretTipGalerieCusaturaDto =
pc.PcManopera == null ? null : pc.PcManopera.TipGalerieLaManopera.PretTipGalerie,
TipLinieCusaturaDto = pc.PcManopera == null ? null : pc.PcManopera.TipLinieLaManopera.NumeTipLinie,
PretTipLinieCusaturaDto =
pc.PcManopera == null ? null : pc.PcManopera.TipLinieLaManopera.PretPeTipLinie,
InelePrindereDto = pc.PcManopera == null ? null : pc.PcManopera.InelPrindereLaManopera!.CuloareInel,
PretInelPrindereDto = pc.PcManopera == null
? null
: pc.PcManopera.InelPrindereLaManopera!.PretPerMetruInele,
MaterialDto = pc.PcManopera == null ? null : pc.PcManopera.MaterialLaManopere.NumeMaterial,
PretMaterialDto = pc.PcManopera == null ? null : pc.PcManopera.MaterialLaManopere.PretMaterial,
})
.ToListAsync();
Код: Выделить всё
PretDto = pc.PcDimensiune == null
? null
: (from pcd in allProductsWithDimensions
where pcd.IdProdus == pc.Produs.IdProdus && pcd.IdDimensiune == pc.PcDimensiune.IdDimensiune
select pcd.Pret).First(),
PretRedusDto = pc.PcDimensiune == null
? null
: (from pcd in allProductsWithDimensions
where pcd.IdProdus == pc.Produs.IdProdus && pcd.IdDimensiune == pc.PcDimensiune.IdDimensiune
select pcd.PretRedus).First(),
Код: Выделить всё
public class ProduseCuComenzi
{
// Attributes
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdProduseCuComenzi { get; set; }
public int NrBucati { get; set; }
// Fk
public int? IdSet { get; set; }
public Seturi? Set { get; set; }
public int IdProdus { get; set; }
public Produse Produs { get; set; } = null!;
public int IdComanda { get; set; }
public Comenzi Comanda { get; set; } = null!;
public int IdCuloare { get; set; }
public Culori PcCuloare { get; set; } = null!;
public int? IdDimensiune { get; set; }
public Dimensiuni? PcDimensiune { get; set; }
public int? IdManopera { get; set; }
public Manopere? PcManopera { get; set; }
}
Код: Выделить всё
public class Dimensiuni
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdDimensiune { get; init; }
[StringLength(4)]
public string Lungime { get; init; } = null!;
[StringLength(4)]
public string Latime { get; init; } = null!;
public bool? PerdeaEstePereche { get; set; }
[StringLength(15)]
public string? RecomandarePat { get; set; }
// navigation props
public ICollection? DProduseCuDimensiuni { get; }
public ICollection? DAsociereSeturi { get; }
public ICollection? DProduseCuComenzi { get; }
Код: Выделить всё
public class ProduseCuDimensiuni
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdProdusCuDimensiune { get; init; }
// Foreign Keys
public decimal Pret { get; set; }
public decimal PretRedus { get; set; }
public int? IdDimensiune { get; set; }
public Dimensiuni? PdDimensiune { get; set; }
public int IdProdus { get; set; }
public Produse PdProduse { get; set; } = null!;}
Подробнее здесь: https://stackoverflow.com/questions/790 ... properties