我的映射定义如下:
Mapper.CreateMap<DsMyDataSet.TMyRow, MyRowDto>();
MyRowDto是TMyRow的一对一拷贝,但所有属性都是自动属性。
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
public string PositionFolder{
get {
try {
return ((string)(this[this.tableTMyDataSet.PositionFolderColumn]));
}
catch (global::System.InvalidCastException e) {
throw new global::System.Data.StrongTypingException("The value for column \'PositionFolder\' in table \'TMyDataSet\' is DBNull.", e);
}
}
set {
this[this.tableTMyDataSet.PositionFolderColumn] = value;
}
}
当我打电话时:
DsMyDataSet.TMyRow row = ....;
AutoMapper.Mapper.Map<MyRowDto>(row);
我遇到了StrongTypingException异常,因为该列中的值为空。属性是可空的,但强类型数据集不支持可空属性,您必须调用IsNullable。 在AutoMapper中如何解决此问题,使映射继续进行(忽略错误并保留null值)?