Skip to content

Expression tree with anonymous type created incorrectly #11127

@NetMage

Description

@NetMage

Please provide a succinct description of the issue.

Consider

let src = [0..10].Select(fun n -> {| n = n |}).ToList().AsQueryable()

let q1 = src.Select(fun c -> {| z = c.n; b = c.n |})
printfn "%A" q1.Expression

let q2 = src.Select(fun c -> {| b = c.n; z = c.n |})
printfn "%A" q2.Expression

Provide the steps required to reproduce the problem:

  1. Run the program

Expected behavior

Both Expression trees passed to Select should call a two argument constructor for the anonymous type directly.

Actual behavior

The first call to Select creates a nested lambda function call using Invoke instead of just passing the arguments to the constructor.

Known workarounds

Putting the fields in the anonymous record in alphabetical order will correct the error.

Related information

This makes EF Core difficult to use with anonymous records.

  • Windows 10
  • .NET Core 5
  • LINQPad

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI-thinks-issue-fixedArea-QuotationsQuotations (compiler support or library). See also "queries"BugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions