Expression tree for inherit access does unneccessary work
Open
@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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.