вы возвращаете несовместимые типы:
public class ServerChartDto
{
.. other values
public DiskSizeInfo DiskSize { get; set; }
}
public class DiskSizeInfo
{
public List<object> Projects { get; set; }
public long Total { get; set; }
}
CreateMap<Organization, ServerChartDto>()
...other mappings
.ForMember(d => d.DiskSize, o => o.MapFrom(s => s.Projects
.Select(y => new DiskSizeInfo
{
Projects =
{
new
{
Name = y.Name,
Used = y.Servers.Sum(z => z.DiskSize)
}
},
Total = y.Servers.Sum(z => z.DiskSize)
}).ToList()))
ServerChartDto.DiskSize имеет тип DiskSizeInfo
ForMember(d => d.DiskSize, o => o.MapFrom(s => s.Projects
.Select(y => new DiskSizeInfo
{
Projects =
{
new
{
Name = y.Name,
Used = y.Servers.Sum(z => z.DiskSize)
}
},
Total = y.Servers.Sum(z => z.DiskSize)
}).ToList()))
в предыдущем коде вы пытаетесь установить d.DiskSize как s.Projects. Выберите (y => y.newDiskSizeInfo ...); который является IEnumerable .
Правильно:
ForMember(d => d.DiskSize, o => o.MapFrom(s => new DiskSizeInfo
{
Projects = s.Projects.Select(y => new
{
Name = y.Name,
Used = y.Servers.Sum(z => z.DiskSize)
}).ToList(),
Total = s.Projects.Sum(x => x.Servers.Sum(y => y.DiskSize)) //I assumed you wanted to sum the DiskSize of the Servers of each project
}))