以下是给定的代码,请问为什么在映射阶段一直出现异常?这两个DTO真的有那么大的区别吗?下面是符号服务器pdb中抛出异常的代码行。
throw new AutoMapperMappingException(context, "Missing type map configuration or unsupported mapping.");
真正让我抓狂的是,@jbogard在AutoMapper的异常处理和仪表化方面做得非常出色,提供了大量源对象和目标对象的上下文数据以及映射器在抛出异常时的状态...但我还是想不通。
void Main()
{
var config = new MapperConfiguration(cfg =>
{
cfg.ShouldMapProperty = p => p.GetMethod.IsPublic || p.GetMethod.IsVirtual;
cfg.CreateMap<Customer, Customer2>()
.ReverseMap();
});
config.AssertConfigurationIsValid();
Customer request = new Customer
{
FirstName = "Hello", LastName = "World"
};
request.FullName = request.FirstName + " " + request.LastName;
Customer2 entity = Mapper.Map<Customer, Customer2>(request);
Console.WriteLine("finished");
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get; set; }
}
[Serializable()]
public partial class Customer2
{
private string _firstName;
private string _lastName;
private string _fullName;
public virtual string FirstName
{
get
{
return this._firstName;
}
set
{
this._firstName = value;
}
}
public virtual string LastName
{
get
{
return this._lastName;
}
set
{
this._lastName = value;
}
}
public virtual string FullName
{
get
{
return this._fullName;
}
set
{
this._fullName = value;
}
}
}
谢谢,Stephen