Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Member does not exist" exception expanding multiple navigation properties within complex type #230

Closed
BlaiseD opened this issue Jan 5, 2025 · 0 comments

Comments

@BlaiseD
Copy link
Member

BlaiseD commented Jan 5, 2025

Source/destination types

    public class RecordStore
    {
        [Key]
        public int RecordStoreId { get; set; }
        [Required]
        [StringLength(150)]
        public string Name { get; set; }
        public Address StoreAddress { get; set; } 
        public List<string> Tags { get; set; } = [];
        public ICollection<Rating> Ratings { get; set; } = [];         
    }
    [Owned]
    public class Address
    {
        [StringLength(200)]
        public string Street { get; set; }
        [StringLength(100)]
        public string City { get; set; }
        [StringLength(10)]
        public string PostalCode { get; set; }
        [StringLength(100)]
        public string Country { get; set; }
        public List<int> RoomNumbers { get; set; } = [];
        public int RecordStoreId { get; set; }
        public virtual ICollection<Door> Doors { get; set; } = [];
    }
    public class Door
    {
        [Key]
        public int Id { get; set; }
        public string Name{ get; set; }
        public int AddressId { get; set; }
        public int DoorManufacturerId { get; set; }
        public int DoorKnobId { get; set; }
        public DoorManufacturer DoorManufacturer { get; set; }
        public DoorKnob DoorKnob { get; set; }
    }
    public class DoorKnob
    {
        [Key]
        public int Id { get; set; }
        public string Style { get; set; }
    }
    public class DoorManufacturer
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class RecordStoreModel
    {
        [Key]
        public int RecordStoreId { get; set; }
        public string Name { get; set; }
        public AddressModel StoreAddress { get; set; } 
        public List<string> Tags { get; set; } = [];
        public ICollection<RatingModel> Ratings { get; set; } = [];         
    }
    [Owned]
    public class AddressModel
    {
        public string Street { get; set; }
        public string City { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public List<int> RoomNumbers { get; set; } = [];
        public int RecordStoreId { get; set; }
        public ICollection<DoorModel> Doors { get; set; } = [];
    }
    public class DoorModel
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public int AddressId { get; set; }
        public int DoorManufacturerId { get; set; }
        public int DoorKnobId { get; set; }
        public DoorManufacturerModel DoorManufacturer { get; set; }
        public DoorKnobModel DoorKnob { get; set; }
    }
    public class DoorKnobModel
    {
        [Key]
        public int Id { get; set; }
        public string Style { get; set; }
    }
    public class DoorManufacturerModel
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
    }

Mapping configuration

    public class AirVinylMappings : AutoMapper.Profile
    {
        public AirVinylMappings()
        {
            CreateMap<Address, AddressModel>()
                .ForAllMembers(o => o.ExplicitExpansion());
            CreateMap<DoorKnob, DoorKnobModel>()
               .ForAllMembers(o => o.ExplicitExpansion());
            CreateMap<Door, DoorModel>()
                .ForAllMembers(o => o.ExplicitExpansion());
            CreateMap<DoorManufacturer, DoorManufacturerModel>()
                .ForAllMembers(o => o.ExplicitExpansion());
            CreateMap<RecordStore, RecordStoreModel>()
                .ForAllMembers(o => o.ExplicitExpansion());
        }
    }

Version: 6.1.0

Expected behavior

Retrieve the list with expansions.

Actual behavior

System.ArgumentException : Member Doors, does not exists in type AutoMapper.OData.EFCore.Tests.AirVinylModel.RecordStoreModel.
  Stack Trace: 
TypeExtensions.GetMemberInfo(Type parentType, String memberName)
ExpansionsHelper.BuildSelectorExpression(Expression sourceExpression, List`1 parts, List`1 memberSelectors, String parameterName) line 81
ExpansionsHelper.BuildSelectorExpression[TSource](List`1 fullName, List`1 memberSelectors, String parameterName) line 46
<>c__DisplayClass2_1`1.<BuildExplicitExpansions>b__1(List`1 include) line 28
ListSelectIterator`2.MoveNext()
List`1.AddRange(IEnumerable`1 collection)
ConcatIterator`1.ToList()
<>c__DisplayClass2_0`1.<BuildExplicitExpansions>g__GetAllExpansions|0(List`1 memberSelectors) line 27
ExpansionsHelper.BuildExplicitExpansions[TSource](IEnumerable`1 includes, List`1 selects) line 18
QueryableExtensions.GetQueryable[TModel,TData](IQueryable`1 query, IMapper mapper, ODataQueryOptions`1 options, QuerySettings querySettings, Expression`1 filter) line 135
QueryableExtensions.GetQueryAsync[TModel,TData](IQueryable`1 query, IMapper mapper, ODataQueryOptions`1 options, QuerySettings querySettings) line 61
<<GetAsync>g__DoGet|0>d.MoveNext() line 141
--- End of stack trace from previous location ---
ExpansionTests.GetAsync[TModel,TData](String query, IQueryable`1 dataQueryable, ODataQueryOptions`1 options, QuerySettings querySettings, String customNamespace) line 131
ExpansionTests.GetAsync[TModel,TData](String query, ODataQueryOptions`1 options, QuerySettings querySettings, String customNamespace) line 118
ExpansionTests.GetRecordStoresCanExpandMultipleNavigationPropertiesOfNavigationPropertyUnderComplexType() line 100
--- End of stack trace from previous location ---

Steps to reproduce

Query /recordstoremodel?$expand=StoreAddress/Doors($expand=DoorManufacturer,DoorKnob)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant