【发布时间】:2019-12-04 20:57:59
【问题描述】:
我有以下代码
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,我该如何使用 automapper?我可以映射集合,但是如何为每个项目调用_fileStorage.GetShortTemporaryLink?
我查看了AfterMap,但我不知道如何从dest 获取FilePath 并将其一一映射到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