Hello,
We have the issue with .net lib AutoMapper 12.0.0
The cause of issue that when we try to call ProjectTo for object with nested object and nested collection it returns EF exception.
"message": "The LINQ expression 'p1 => new Class3DTO
{ Name= p1.Name }\r\n' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.",
When we call only object with nested collection everything works proper.
Please review the classes structure below:
public class Class1DTO {
public Class1DTO () { }
public int Id { get; set; }
public Class2DTO { get; set; }
}
public class Class2DTO {
public Class2DTO () { }
public int Id { get; set; }
public ICollection<Class3DTO> Class3DTOCollection { get; set; }
}
public Class3DTO {
public int Id { get; set; }
public string Name {get; set;}
}
Mapper profile is simple like
CreateMap<Class1, Class1DTO>();
CreateMap<Class2, Class2DTO>();
CreateMap<Class3, Class3DTO>();
The query is also simple.
return Task.FromResult(_repository.GetAll().ProjectTo<Class1DTO>(this._mapper.ConfigurationProvider));
We have tried different configs and queries.
Please advice.
Thank you,
Ksenia Fadeeva