【发布时间】:2021-04-30 07:51:21
【问题描述】:
我在将具有属性的简单类转换为具有属性的类时遇到问题,这些属性本身也称为 ProductDataField
public class ProductDataField
{
public string Value { get; set; }
public string Name{ get; set; }
}
来源:
public class ProductDetailsViewModel
{
public CultureInfo Language { get; set; }
public string SeoTitle { get; set; }
public string SeoDescription { get; set; }
public string SeoKeywords { get; set; }
public string ProductFamily { get; set; }
}
目的地:
public class DetailsComplexViewModel
{
public ProductDataField Language { get; set; }
public ProductDataField SeoTitle { get; set; }
public ProductDataField SeoDescription { get; set; }
public ProductDataField SeoKeywords { get; set; }
public ProductDataField ProductFamily { get; set; }
}
我正在尝试将 ProductDataField 中的“Name”属性映射到“ProductDetailsViewModel”中的属性名称,并将“Value”属性映射到该属性的值。
我尝试使用 CreateMap 映射它们,但我总是遇到类似的错误
“表达式 'x => x.ProductFamily.Value' 必须解析为顶级成员,而不是任何子对象的属性”
任何帮助将不胜感激
【问题讨论】:
标签: c# asp.net mapping automapper automapping