Skip to content

Unused let in the LINQ expression changes result of Query #402

Closed

Description

@SergeiPavlov
(from invoice in Session.Query.All<Invoice>()
    let foo = invoice.InvoiceId.In(nonExistingIds) // This line incorrectly works as additional filter.
                                                                        // Must not have any impact
    where invoice.InvoiceId.In(existingIds)
    select invoice).Count();

The expression:

{All().Select(invoice => new <>f__AnonymousType231`2(invoice = invoice, foo = invoice.InvoiceId.In(value(Xtensive.Orm.Tests.Linq.InTest+
<>c__DisplayClass37_0).nonExistingIds))).Where(<>h__TransparentIdentifier0 => 
<>h__TransparentIdentifier0.invoice.InvoiceId.In(value(Xtensive.Orm.Tests.Linq.InTest+<>c__DisplayClass37_0).existingIds)).Select(<>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.invoice)}

The test to reproduce it:
https://github.com/DataObjects-NET/dataobjects-net/pull/401/files

Looks like let works as where filter.

It is a simlified example.
In the real app we discovered the same effect with used variable in let.

We thought the behavior changed after merging https://github.com/dataObjects-net/dataobjects-net commits for last 7 months.
But after some investigation I see the bug is here for longer time, may be from the beginning.

Activity

  1. changed the title [-]Unused `let` in the LINQ expression makes query incorrect[/-] [+]Unused `let` in the LINQ expression changes result of Query[/+] on Oct 31, 2024
  2. alex-kulakov commented on Dec 4, 2024

    @alex-kulakov
    Contributor

    Two problems were discovered during investigation of this case

    • incorrect visit of GroupBy key expression
    • wrong mapping of Include provider which lead to incorrect reference to source collection for IN statement.

    First issue appeared after changes released in 6.0.13 and traversed to newer branches via merge.

    @SergeiPavlov the PR that fixes both of issues, and because root of at least one of problems lied in 6.0 branch I had to resolve it there. Soon these changes will be merged into newer branches

  3. added a commit that references this issue on Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions