成员的Automapper自定义配置仅支持类型上的顶级单个成员 [英] Automapper Custom configuration for members is only supported for top-level individual members on a type
本文介绍了成员的Automapper自定义配置仅支持类型上的顶级单个成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试映射从数据库中获得的结果,并且我具有以下模型
I am trying to map a result I get from database and I have the following models
public class ClientTest
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ClientTestDto
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ClientDbItem
{
public ClientTest Client { get; set; }
public Address Address { get; set; }
}
public class Address
{
public int Id { get; set; }
public string Value { get; set; }
}
和以下映射
CreateMap<ClientTest, ClientTestDto>();
CreateMap<ClientDbItem, ClientTestDto>()
.ForMember(dest => dest, opt => opt.MapFrom(src => src.Client));
运行软件时,我会得到
仅顶级成员支持成员的自定义配置一个类型上的单个成员
Custom configuration for members is only supported for top-level individual members on a type
如果我先为ClientTest和ClientTestD创建配置,为什么会发生这种情况?
Why is that happening If I am creating the config for ClientTest and ClientTestDto first?
推荐答案
为此有一个特殊的API, IncludeMembers
.请参见此处.
There's a special API for that, IncludeMembers
. See here.
这篇关于成员的Automapper自定义配置仅支持类型上的顶级单个成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文