[英]Map two or more properties to one property in automapper
我試圖在自動映射器中將兩個字符串映射到一個字符串。
我認為這與使用此功能有關 ,但我無法理解。
這是錯誤的,但類似這樣:
CreateMap<TestClass, SecondClass.ThirdClass>.ForMember(x => x.Test, y => y.MapFrom(z => z.FirstString && z => z.SecondString))
public class TestClass {
public string FirstString { get; set; }
public string SecondString { get; set; }
}
public class SecondClass {
public class ThirdClass {
public string Test { get; set; }
}
}
我想測試包含FirstString + SecondString。
您可以只使用字符串插值y => y.MapFrom(z => $"{z.FirstString} {z.SecondString)}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.