Entweder schreiben Sie die Abfrage in eine Form um, die übersetzt werden kann, oder wechseln Sie explizit zur Kundenauswertung, indem Sie einen Aufruf von „AsEnumerable“, „AsAsyncEnumerable“, „ToList“ oder „ToListAsync“ einfügen.
Ich versuche, eine Abfrage zu schreiben, um einige Bestelldetails zusammen mit ihren Produkten abzurufen (die haben Farbe, Größe usw.). Ich verwende eine Projektion, muss aber auf einige tief verschachtelte Eigenschaften zugreifen, um den Preis pro Dimension zu erhalten.
UPDATE: Hier hole ich alle Daten aus der Join-Tabelle ab:
Code: Select all
var allProductsWithDimensions = await productsOnDimensionsRepository.GetAllAsync();
Code: Select all
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();
Code: Select all
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(),
Code: Select all
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; }
}
Code: Select all
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; }
}
Code: Select all
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!;
}
ENDGÜLTIGES UPDATE – LÖSUNG (etwas übertrieben, aber ich kann nichts anderes finden):
Code: Select all
PretDto = ord.PcDimensiune.DProduseCuDimensiuni!
.First(pd => pd.IdDimensiune == ord.PcDimensiune.IdDimensiune &&
pd.IdProdus == ord.Produs.IdProdus).Pret,
PretRedusDto = ord.PcDimensiune.DProduseCuDimensiuni!
.First(pd => pd.IdDimensiune == ord.PcDimensiune.IdDimensiune &&
pd.IdProdus == ord.Produs.IdProdus).PretRedus,
Full version