Skip to content

Members with custom mapping definitions not populated unless $select is used #196

@radlohac

Description

@radlohac

Starting from the samples in this repo, let's make OpsTenant.BuildingIds a List<int> and add a mapping:

Source/destination types

    public class OpsTenant : BaseOpsTenant
    {
        [Key]
        public Guid Identity { get; set; }
        public DateTime CreatedDate { get; set; }
        public List<int> BuildingIds { get; set; }
        public ICollection<CoreBuilding> Buildings { get; set; }
    }

Mapping configuration

            CreateMap<TMandator, OpsTenant>()
                .ForMember(d => d.BuildingIds, o => o.MapFrom(s => s.Buildings.Select(b => b.Id).ToList()))
                .ForAllMembers(o => o.ExplicitExpansion());

Version: 4.0.1

Expected behavior

BuildingIds should be populated when calling:
http://localhost:16324/opstenant

Actual behavior

BuildingIds is not populated by default unless I explicitly $select it:
http://localhost:16324/opstenant?$select=Identity,Name,CreatedDate,BuildingIds

I think this is an issue as it is not consistent with the other members behavior. BuildingIds is a simple member with a custom mapping, it is neither a navigation nor complex property, $expand won't work. To be forced to $select in order to access the data is not intuitive and also not practical as it requires to explicitly $select all other properties in order to get the default structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions