具有操作的自动映射器地图集合

问题描述 投票:2回答:1

我有以下代码

IList<ConfigurationDto> result = new List<ConfigurationDto>();
foreach (var configuration in await configurations.ToListAsync())
{
    var configurationDto = _mapper.Map<ConfigurationDto>(configuration);
    configurationDto.FilePath = _fileStorage.GetShortTemporaryLink(configuration.FilePath);
    result.Add(configurationDto);
}
return result;

如果foreach,我该如何使用自动映射器?我可以映射集合,但是如何为每个项目调用_fileStorage.GetShortTemporaryLink

我看过AfterMap,但我不知道如何从FilePath中获取dest并将其一一映射到src。我可以使用自动映射器吗?

public class ConfigurationDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Version { get; set; }
    public DateTime CreateDateTime { get; set; }
    public long Size { get; set; }
    public string FilePath { get; set; }
}
c# .net asp.net-core automapper
1个回答
0
投票

您可以使用IValueResolver接口来配置您的地图,以从函数中映射属性。像波纹管样的东西。

© www.soinside.com 2019 - 2024. All rights reserved.