【发布时间】:2015-12-07 07:05:54
【问题描述】:
我得到了这个例外 -
缺少类型映射配置或不支持的映射。
映射类型: 列表`1 -> 我的类型
System.Collections.Generic.List`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] -> MyAssebmly.MyType
MyType 只是另一个具有必要属性的 POCO。
我的代码是 -
Mapper.CreateMap<AnotherType, MyType>()
.ConvertUsing<CustomTypeResolver>();
在哪里
internal class CustomTypeResolver : AutoMapper.ITypeConverter<AnotherType,
MyType>
{
//EDIT
public MyType Convert(ResolutionContext context)
{
return new MyType { MyList = new List<T> { new T { ... } } };
}
}
internal class MyType
{
public List<T> MyList { get; set; }
}
任何人都知道出了什么问题。
【问题讨论】:
-
我不明白泛型类型参数是如何工作的。
T在 CustomTypeResolver 中是如何定义的? -
你能显示实际的映射调用吗?
-
在完成所有 Automapper 设置(
CreateMap等...)之后,您是否致电Mapper.AssertConfigurationIsValid?
标签: c# automapper