From 17fc22cdb45e32a0cd14d03fce2504785e444f7b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 28 Oct 2023 23:22:58 +0200 Subject: [PATCH] Fix eager includes not working --- samples/BasicSample/Program.cs | 12 ++++++++++++ .../Services/ProjectableExpressionReplacer.cs | 3 +++ 2 files changed, 15 insertions(+) diff --git a/samples/BasicSample/Program.cs b/samples/BasicSample/Program.cs index 08c25fc..d724d99 100644 --- a/samples/BasicSample/Program.cs +++ b/samples/BasicSample/Program.cs @@ -200,6 +200,18 @@ namespace BasicSample Console.WriteLine($"Our users bought the following products starting with 'Red': {string.Join(", ", result.Ordered)}"); } + { + var ret = dbContext.Users + .Include(x => x.Orders) + .ThenInclude(x => x.Items) + .ThenInclude(x => x.Product) + .First(); + Console.WriteLine($"User name: {ret.FullName}, Orders: {string.Join(", ", ret.Orders + .SelectMany(x => x.Items + .Select(y => y.Product.Name) + ))}"); + } + } } } diff --git a/src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs b/src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs index da14c3a..6c631ef 100644 --- a/src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs +++ b/src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs @@ -255,6 +255,9 @@ namespace EntityFrameworkCore.Projectables.Services var properties = entityType.GetProperties() .Where(x => !x.IsShadowProperty()) .Select(x => x.GetMemberInfo(false, false)) + .Concat(entityType.GetNavigations() + .Where(x => !x.IsShadowProperty()) + .Select(x => x.GetMemberInfo(false, false))) // Remove projectable properties from the ef properties. Since properties returned here for auto // properties (like `public string Test {get;set;}`) are generated fields, we also need to take them into account. .Where(x => projectableProperties.All(y => x.Name != y.Name && x.Name != $"<{y.Name}>k__BackingField"));