AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Support for casting in $expand #199

Open orty opened 7 months ago

orty commented 7 months ago

On the legacy OData library, the support for cast in $expand expression has been added with the following PR https://github.com/OData/odata.net/pull/2300

Quote from the OData repository: (...)~/Orders?$expand=Customer/Model.VipCustomer This means that we will expand only the Customers that are an instance of Model.VipCustomer. Note: Model.VipCustomer is a derived type of the Customer.

This behavior does not seem to be supported by this library so far. I tried to tweak the AutoMapper.AspNet.OData.LinqExtensions.GetExpansions‎(IEnumerable<SelectItem>‎ selectedItems‎,‎ Type‎ parentType‎,‎ IEdmModel‎ edmModel‎) method to do so, but the furthest I can get to is to force the parentType to the derived type specified by the query. As it does not "trim" out the other derived types (or base type either), if the property I need to $select or whatever inside my $expand is only declared in my specific derived type, I receive errors of a missing member.

@BlaiseD is this something you plan to support with your library ?

Thanks

orty commented 7 months ago

Adding reference to proposed PRs on both AutoMapper.Extensions.OData #200 and LogicBuilder.DataComponents #44