question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Projection mapping is not updated when set operation within pending collection

See original GitHub issue

I am not getting correct result when using “Union” inside the select of objects in Linq query.

My requirement is that I need to match mapper table and get the details by combining two column values into single and return to the object inside “select” statement in linq query. Hence I used “Union” in this scenario.

Sample Query:

var resultCollection = (from studentGroup in context.StudentGameMapper
                                     where studentGroup.GroupId==6
                                     select new StudentGameResult
                                     {
                                         GroupId= studentGroup.GroupId
                                         StudentId= studentGroup.StudentId
                                         SportsList= (from inDoorSports in Context.InDoorSports
                                                                   && inDoorSports.Id == studentGroup.InCategoryId
                                                                   select inDoorSports.Name)
                                                             .Union(from outDoorSports in Context.OutDoorSports
                                                                     && outDoorSports.Id == studentGroup.OutCategoryId
                                                                     select outDoorSports.Name).ToList()
                                      })).AsQueryable();

For each student, I am getting either first value of “InDoorSports” or “OutDoorSports” even if the student have value for both the sports category column.

Note: If I directly fetch the result of sport name alone by using “Union” I can get full values. But when used “Union” inside “select” statement object I am not getting expected value.

var resultCollection = (from inDoorSports in Context.InDoorSports && inDoorSports.Id == 1 
                                     select inDoorSports.Name)
                                    .Union(
                                    from outDoorSports in Context.OutDoorSports 
                                    && outDoorSports.Id == 1 
                                    select outDoorSports.Name).AsQueryable();

Kindly let me know is this an issue or anything wrong in my query.

Further technical details EF Core version: 3.0.0 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL Target framework: .NET Core 3.0 IDE: Visual Studio 2019 16.3.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Nov 8, 2019

Track separately.

0reactions
rojicommented, Nov 7, 2019

After some investigation, this looks like a dup of #17337 (loss of referential integrity).

The projection with the union is in the pending collections. When CollectionJoinApplyingEV processes the query, it pushes down the query before applying the CROSS APPLY (as there’s a Limit). As part of this, the pending collections are remapped with SqlRemappingVisitor, to modify the ColumnExpressions referring to the query being pushed down. As a result, the UnionExpression in the pending collection’s SelectExpression changes; but nobody changes that SelectExpression’s projection mapping, so the column continues to refer to the old UnionExpression. As a result it has the wrong alias.

Learned quite a lot from this one…

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core Union on IQueryable fails with Unable to translate ...
System.InvalidOperationException: Unable to translate set operation after client projection has been applied. Consider moving the set operation ...
Read more >
Troubleshooting Operator issues - OpenShift Documentation
When UPDATED is True and UPDATING is False, there are no pending changes. In the previous example, the worker node has pending changes....
Read more >
StackSets concepts - AWS CloudFormation
A stack set lets you create stacks in AWS accounts across regions by using a ... When you create, update, or delete stacks,...
Read more >
Monitoring progress with replication metrics and S3 Event ...
Monitor the progress of replication with S3 Replication metrics by tracking bytes pending, operations pending, and replication latency.
Read more >
Perform Two Phase Commits
Use the following update() operation to set remove the pending transaction from the documents in the accounts collection:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found