Skip to content

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

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.

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