【发布时间】:2013-11-21 14:23:08
【问题描述】:
我有这样定义的映射:
Mapper.CreateMap<DsMyDataSet.TMyRow, MyRowDto>();
MyRowDto 是 TMyRow 的 1:1 副本,但所有属性都是自动属性。
[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 instea。 如何在 AutoMapper 中解决此问题,以便进行映射(忽略错误并保留空值)?
【问题讨论】:
标签: c# automapper strongly-typed-dataset