OData / OData/AspNetCoreOData

Expression tree for inherit access does unneccessary work

Open
#496 2 comments 1 reaction 1 assignee View on GitHub

@KenitoInc is already working on this.

Since Feb 22, 2022.

investigating
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

The expression tree for a select query does silly type checks:

public record Student(int Id, string Name, DateTime Time, int Version = 0) : Res(Id);

public abstract record Res(int Id);
.Lambda #Lambda1<System.Func`2[TestOData.Student,Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome`1[TestOData.Student]]>(TestOData.Student $$it)
{
    .New Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome`1[TestOData.Student](){
        Model = .Constant<Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]>(Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]).TypedProperty,
        Container = .New Microsoft.AspNetCore.OData.Query.Container.PropertyContainer+NamedPropertyWithNext0`1[System.Nullable`1[System.Int32]]()
        {
            Name = "Id",
            Value = .If ($$it .As TestOData.Res == null) {
                null
            } .Else {
                (System.Nullable`1[System.Int32])($$it .As TestOData.Res).Id
            },
            Next0 = .New Microsoft.AspNetCore.OData.Query.Container.AutoSelectedNamedProperty`1[System.Nullable`1[System.Int32]](){
                Name = "Version",
                Value = .If ($$it == null) {
                    null
                } .Else {
                    (System.Nullable`1[System.Int32])$$it.Version
                }
            }
        }
    }
}

$$it .As TestOData.Res is ALWAYS true, and the type of the value is always same in SelectSome. Therefore the entire inner access could be done as:

.Lambda #Lambda1<System.Func`2[TestOData.Student,Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome`1[TestOData.Student]]>(TestOData.Student $$it)
{
    .New Microsoft.AspNetCore.OData.Query.Wrapper.SelectSome`1[TestOData.Student](){
        Model = .Constant<Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]>(Microsoft.AspNetCore.OData.Query.Container.LinqParameterContainer+TypedLinqParameterContainer`1[Microsoft.OData.Edm.IEdmModel]).TypedProperty,
        Container = .New Microsoft.AspNetCore.OData.Query.Container.PropertyContainer+NamedPropertyWithNext0`1[System.Nullable`1[System.Int32]]()
        {
            Name = "Id",
            Value = $$it.Id,
            Next0 = .New Microsoft.AspNetCore.OData.Query.Container.AutoSelectedNamedProperty`1[System.Nullable`1[System.Int32]](){
                Name = "Version",
                Value = $$it.Version
           }
        }
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.