WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Incorrect OData query when collection is mapped as property using converter

Open maumar opened this issue 4 years ago • 2 comments

issue found by @keatkeat87 and originally filed here: https://github.com/dotnet/efcore/issues/19628

Repro: 1.git clone https://github.com/keatkeat87/odata--select-HasConversion-issue.git 2.dotnet ef migrations add init 3.dotnet ef database update 4.F5 5.visit /odata/Products?$select=images

Problem here is that images is mapped as a property mapped using EFCore converters into json. However OData still recognizes it as a navigation collection, producing the following query:

DbSet<Product>()
    .Select(namelessParameter{0} => new SelectSome<Product>{ 
        ModelID = TypedLinqParameterContainer<string>.TypedProperty, 
        Container = new NamedPropertyWithNext0<IEnumerable<SelectAll<Image>>>{ 
            Name = "images", 
            Value = namelessParameter{0}.images
                .Select(namelessParameter{1} => new SelectAll<Image>{ 
                    ModelID = TypedLinqParameterContainer<string>.TypedProperty, 
                    Instance = namelessParameter{1}, 
                    UseInstanceForProperties = True 
                }), 
            Next0 = new AutoSelectedNamedProperty<Nullable<int>>{ 
                Name = "Id", 
                Value = (Nullable<int>)namelessParameter{0}.Id 
            }
        }
    } )

maumar avatar Sep 03 '20 01:09 maumar

@xuzhg Are there any plans to fix this. My team is also running into this issue. Thanks for the help!

Lusey77 avatar May 12 '22 23:05 Lusey77

@maumar @Lusey77 From Microsoft.AspnetCore.OData v8.0.4, we can custom the SelectExpandBinder to generate a preferred LinQ expression

KenitoInc avatar May 18 '22 08:05 KenitoInc