diff --git a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs index 795cd6d7b5d..6986097701a 100644 --- a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs +++ b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.ChangeTracking; @@ -1919,6 +1920,31 @@ public virtual void Lazy_loading_finds_correct_entity_type_with_alternate_model( } } + [ConditionalFact] + public virtual void Top_level_projection_track_entities_before_passing_to_client_method() + { + using (var context = CreateContext(lazyLoadingEnabled: true)) + { + var query = (from p in context.Set() + select DtoFactory.CreateDto(p)).FirstOrDefault(); + + Assert.NotNull(((dynamic)query).Single); + } + } + + private static class DtoFactory + { + public static object CreateDto(Parent parent) + { + return new + { + parent.Id, + parent.Single, + parent.Single.ParentId + }; + } + } + public class Address { public int AddressId { get; set; } diff --git a/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs index bec12e1f318..0b1d20fad96 100644 --- a/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs @@ -429,6 +429,21 @@ public override async Task Load_collection(EntityState state, bool async) } } + [ConditionalFact(Skip = "Issue#1015")] + public override void Top_level_projection_track_entities_before_passing_to_client_method() + { + base.Top_level_projection_track_entities_before_passing_to_client_method(); + + Assert.Equal( + @"@__p_0='707' (Nullable = true) + + SELECT [e].[Id], [e].[ParentId] + FROM [Child] AS [e] + WHERE [e].[ParentId] = @__p_0", + Sql, + ignoreLineEndingDifferences: true); + } + protected override void ClearLog() => Fixture.TestSqlLoggerFactory.Clear(); protected override void RecordLog() => Sql = Fixture.TestSqlLoggerFactory.Sql;