-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF 6.0.0 and 6.0.1: sub-lists are no longer loaded #27105
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
@smitpatel Confirmed regression on 6.0. SQL generated in 5.0: SELECT [e].[Id], [t].[Id], [t].[Id0], [t].[Prop]
FROM [EntityOnes] AS [e]
LEFT JOIN (
SELECT [e0].[Id], [e1].[Id] AS [Id0], [e1].[Prop], [e0].[EntityOneId]
FROM [EntityTwo] AS [e0]
LEFT JOIN [EntityThree] AS [e1] ON [e0].[Id] = [e1].[EntityTwoId]
) AS [t] ON [e].[Id] = [t].[EntityOneId]
ORDER BY [e].[Id], [t].[Id], [t].[Id0] Code: public class EntityOne
{
public Guid Id { get; set; }
public List<EntityTwo> ListA { get; set; }
}
public class EntityTwo
{
public Guid Id { get; set; }
public List<EntityThree> ListB { get; set; }
}
public class EntityThree
{
public Guid Id { get; set; }
public string Prop { get; set; }
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
public DbSet<EntityOne> EntityOnes { get; set; }
public DbSet<EntityTwo> EntityTwos { get; set; }
public DbSet<EntityTwo> EntityThrees { get; set; }
}
public class Program
{
public static void Main()
{
using (var context = new SomeDbContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var result = context.Set<EntityOne>()
.Select(x =>
new
{
x.Id,
ListWithSubList = x.ListA.Select(b =>
b.ListB.Select(o => new
{
o.Id, o.Prop
}))
})
.ToList();
}
}
} |
smitpatel
added a commit
that referenced
this issue
Jan 6, 2022
We copied type from subquery itself which is always Queryable type because of conversion we do. We need to convert it back to enumerable. Issue happens only when nested level because we use element type so for 1 level queryable is gone. But for nested level we get Queryable<T> as element type on outer which is not assignable from List<T> The conversion doesn't cause issue with user having Queryable in the result since that throws exception much earlier. Resolves #27105
We will discuss in triage if we want to patch this. Created PR against 6.0 for now. |
smitpatel
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Jan 6, 2022
smitpatel
added a commit
that referenced
this issue
Jan 10, 2022
We copied type from subquery itself which is always Queryable type because of conversion we do. We need to convert it back to enumerable. Issue happens only when nested level because we use element type so for 1 level queryable is gone. But for nested level we get Queryable<T> as element type on outer which is not assignable from List<T> The conversion doesn't cause issue with user having Queryable in the result since that throws exception much earlier. Resolves #27105
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Description
After upgrading from 5.0.13 to 6.0.0 or 6.0.1, I can no longer load sublists and instead get an exception.
Exception Details
Code
A repository to demonstrate the bug can be found here:
https://github.com/MarcDrexler/EfCorePopulateCollectionProblem
To verify the problem, simply press F5 and it will throw the exception.
Connection string and database is not needed.
Provider and version information
EF Core version: tested in 6.0.0 + 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.1
The text was updated successfully, but these errors were encountered: