AutoMapper / AutoMapper.Extensions.OData

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

Missing and wildcard selects omit complex type properties #99

Closed AbdullahUlber closed 3 years ago

AbdullahUlber commented 3 years ago

Missing and wildcard selects should include all structural properties (see http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#_Toc31361040), but the current implementation only includes literal types and therefore omits complex type properties.

internal static class TypeExtensions
    {
        public static MemberInfo[] GetSelectedMembers(this Type parentType, List<string> selects)
        {
            if (selects == null || !selects.Any())
                return parentType.GetValueTypeMembers();

            return selects.Select(select => parentType.GetMemberInfo(select)).ToArray();
        }

        private static MemberInfo[] GetValueTypeMembers(this Type parentType)
        {
            if (parentType.IsList())
                return new MemberInfo[] { };

            return parentType.GetMemberInfos().Where
            (
                info => (info.MemberType == MemberTypes.Field || info.MemberType == MemberTypes.Property)
                && info.GetMemberType().IsLiteralType()
            ).ToArray();
        }

The current implementation lacks the information required to distinguish between a navigation property and a complex type property. This information is however available in the EDM model.

BlaiseD commented 3 years ago

A PR is welcome.