Closed agateeno closed 2 years ago
Differences are expected (because Get uses Map and GetQuery uses projection). The tests should help you figure out the configuration for your use case.
Ok to refer to the broken code if you think there is a bug.
I want to use the GetQuery method for performance issues. How can I solve this?
First see if ProjectTo
works by itself - otherwise maybe you're going in the wrong direction. It looks like you're expecting it to return multiple implementations of that child reference in the same instance i.e. what is SomeClass
in Child = new SomeClass { }
.
Get
uses includes, GetQuery
(projection) uses a LINQ select.
TestBugAutomapperOData.zip (Please refer to the example I uploaded in this issue)
In class SharedODataController, the line 37 returns this:
{ "@odata.context":"https://localhost:7048/odata/$metadata#Main(Child())", "value":[ { "Id":1, "Child":{ "Id":1, "Name":"name-01" } }, { "Id":2, "Child":{ "Id":2, "Name":"name-02" } }, { "Id":3, "Child":{ "Id":3, "Name":"name-03" } } ] }
line 38 returns this (and that's correct):
{ "@odata.context":"https://localhost:7048/odata/$metadata#Main(Child())", "value":[ { "Id":1, "Child":{ "Id":1, "Name":"name-01", "NameOne1":"name-01-01" } }, { "Id":2, "Child":{ "Id":2, "Name":"name-02", "NameTwo1":"name-02-01", "NameTwo2":"name-02-02" } }, { "Id":3, "Child":{ "Id":3, "Name":"name-03", "NameThree1":"name-03-01", "NameThree2":"name-03-02", "NameThree3":"name-03-03" } } ] }
You can execute by launching in your browser "https://localhost:7048/odata/Main?$expand=Child". If you want to pick the single child element: https://localhost:7048/odata/One / https://localhost:7048/odata/Two / https://localhost:7048/odata/Three
Version of .NET: 6.0.8 Version of packages: AutoMapper.AspNetCore.OData.EFCore 3.0.5 AutoMapper.Extensions.Microsoft.DependencyInjection 11.0.0 Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 6.0.8 Microsoft.AspNetCore.Identity.EntityFrameworkCore 6.0.8 Microsoft.AspNetCore.OData 8.0.11