-
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
Misinterpreted expression with owned entities #20729
Comments
@verdie-g This is working for me with EF Core 5.0 preview 3. Can you try again with preview 3 and check that it resolves your issue? Note for team: this was not an in-memory issue; it also reproed on SQL Server. |
The issue is still present on my side using |
@verdie-g Can you extract the IQueryable into a variable: var queryable = db.Owners.ProjectTo<OwnerViewModel>(config);
var c = await queryable.ToListAsync(); And then drill down into it in the debugger, expand the DebugView, and post here both the Expression and Query. On my machine I see this:
SELECT [o].[Id], CAST(0 AS bit), CASE
WHEN [o0].[Id] IS NULL THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END, [o0].[Id], [o].[Owned1_A]
FROM [Owners] AS [o]
LEFT JOIN [Other] AS [o0] ON [o].[O_OtherId] = [o0].[Id] |
Looks pretty similar DbSet<Owner>()
.Select(dtoOwner => new OwnerViewModel{
Id = dtoOwner.Id,
O = dtoOwner.O == null ? null : new Owned2ViewModel{ Other = dtoOwner.O.Other == null ? null : new OtherViewModel{ Id = dtoOwner.O.Other.Id }
}
,
Owned1 = dtoOwner.Owned1 == null ? null : new Owned1ViewModel{ A = dtoOwner.Owned1.A }
}
) And no query for InMemory provider. |
@verdie-g Thanks--it was my error. I didn't check again with the in-memory provider. I can now repro this on the latest daily build. |
… to weak type Resolves #20729 The issue here was, when adding navigation to weak type, we generate GJ-DIE-SM pattern in which we push current projection to outer element. During the process we updated value buffer indexes for entity projections, some of them were being nested entity projection for weak types. This indexes differed from what it was earlier when the earlier navigation was expanded and put into the tree. Giving us incorrect expression to translate in projection. Fix is to maintain original indexes and add a dummy one if needed. For EntityProjections, each slot would represent reading 1 property value so we can just put the same value in same slot. For non-entity projections, each slot can have complex value. We put this value in whatever next slot is. With projection binding it should bind correctly when translating.
… to weak type Resolves #20729 The issue here was, when adding navigation to weak type, we generate GJ-DIE-SM pattern in which we push current projection to outer element. During the process we updated value buffer indexes for entity projections, some of them were being nested entity projection for weak types. This indexes differed from what it was earlier when the earlier navigation was expanded and put into the tree. Giving us incorrect expression to translate in projection. Fix is to maintain original indexes and add a dummy one if needed. For EntityProjections, each slot would represent reading 1 property value so we can just put the same value in same slot. For non-entity projections, each slot can have complex value. We put this value in whatever next slot is. With projection binding it should bind correctly when translating.
… to weak type (#22202) Resolves #20729 The issue here was, when adding navigation to weak type, we generate GJ-DIE-SM pattern in which we push current projection to outer element. During the process we updated value buffer indexes for entity projections, some of them were being nested entity projection for weak types. This indexes differed from what it was earlier when the earlier navigation was expanded and put into the tree. Giving us incorrect expression to translate in projection. Fix is to maintain original indexes and add a dummy one if needed. For EntityProjections, each slot would represent reading 1 property value so we can just put the same value in same slot. For non-entity projections, each slot can have complex value. We put this value in whatever next slot is. With projection binding it should bind correctly when translating.
I have one entity (
Owner
) containing two owned entities (Owned1
andOwned2
). When selecting a row and projecting it usingAutoMapper
I expected both owned entities to be different than null but one of them always gets null. If I remove one owned entity the other becomes different than null. Also, if I replace the navigation property ofOwned2
and replace it with an int, both entities aren't null anymore.I've reported the issue to AutoMapper but apparently the issue would be on EF's side.
Feel free to rename the title as I haven't understand the issue.
Steps to reproduce
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.InMemory
Target framework: .NET Core 3.1
Operating system: 5.6.3-arch1-1 x86_64 GNU/Linux
IDE: Rider 2020.1
The text was updated successfully, but these errors were encountered: