Closed andyfurniss4 closed 1 year ago
That usually means ExplicitExpansion is missing somewhere in your profile.
You might find the tests helpful.
@BlaiseD My understanding was that you only needed to set ExplicitExpansion
for complex types. However, I just changed my profile from:
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Infrastructure.Entities.Thing, ThingDto>()
.ForMember(t => t.ChildThings, o => o.ExplicitExpansion());
CreateMap<Infrastructure.Entities.ChildThing, ChildThingDto>();
}
}
To this:
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Infrastructure.Entities.Thing, ThingDto>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<Infrastructure.Entities.ChildThing, ChildThingDto>();
}
}
And now it works! So I guess my assumption was wrong. Does it apply to reference types of all kinds?
I have another question. I'm trying to apply a filter within an expand. I'd expect this filter to apply to the expanding collection so that only one child object is returned/queryed, however it's still returning all of them.
http://localhost:5100/things?$expand=childThings($filter=number eq 1)
SELECT [t].[Id], [t].[Name], [c].[Id], [c].[Number]
FROM [Things] AS [t]
LEFT JOIN [ChildThings] AS [c] ON [t].[Id] = [c].[ThingId]
ORDER BY [t].[Id]
I have enabled ExplicitExpansion
for all members of both objects in my profile.
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Infrastructure.Entities.Thing, ThingDto>()
.ForAllMembers(o => o.ExplicitExpansion());
CreateMap<Infrastructure.Entities.ChildThing, ChildThingDto>()
.ForAllMembers(o => o.ExplicitExpansion());
}
}
I can see from the unit tests that this should work but I must have missed something. Any ideas?
Thank you very much for your help.
Not for the libraries in this repository - see the ReadMe. The expansions for value types are automatically added unless a $select
is specified.
Got a bit of an issue with the
select
parameter. I'm not sure if I've set something up wrong but it doesn't seem to be excluding fields that I have not explicitly requested. I've tried debugging through the AutoMapper code and it seems to know that I only want one property - I can see it build the lambda for that property in theQueryableExtensions.GetQueryable
method - but somewhere between that and executing the SQL, it loses track.Versions
AutoMapper.AspNetCore.OData.EFCore: 4.0.0 Microsoft.EntityFrameworkCore.SqlServer: 6.0.16
Source/destination types
Mapping configuration
Setup
Controller
Query
http://localhost:5100/things?select=id
SQL executed
Expected behavior
Array of objects, with only the ID value of each object returned. Database only queried for Id value (not Name).
Actual behavior
Array of objects, with both the ID and Name values of each object returned. E.g.