Automapper 将多个属性转换为 array/list

Automapper convert multiple properties into array/list

我们的数据库由 firstname1 和 firstname2 等属性构成

不幸的是,我无法修改数据库,所以我至少想要 return 一个名字列表..我怎样才能让自动映射器转向

public class dto 
{
  public string firstname1;
  public string firstname2;
}

成数组

public class viewmodel 
{
  public string firstname;
}

您可以将 lambda 传递给 ResolveUsing:

.ForMember(f => f.Value, o => o.ResolveUsing(b =>
    {
        // Combine your firstnames here...
        return new[]{ b.firstname1, b.firstname2 };
    }
));