using (IDataReader dr = DatabaseContext.ExecuteReader(command))
{
if (dr.Read())
{
AutoMapper.Mapper.CreateMap<IDataReader, ProductModel>();
return AutoMapper.Mapper.Map<IDataReader, IList<ProductModel>>(dr);
}
return null;
}
如果博士有只有一排-> 错误:抛出类型为“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”的异常
如果博士有多于一排,它运行ok.
有什么帮助吗?
问题是 Automapper 也调用 Read() - 因此总是尝试查看第二条记录。如果您考虑一下,如果读取器中有 1000 行,AutoMapper 如何将其转换为列表而不调用 Read() 来遍历它们?
更改您的线路以拨打 HasRows
e.g.
using (IDataReader dr = DatabaseContext.ExecuteReader(command))
{
if (dr.HasRows)
{
AutoMapper.Mapper.CreateMap<IDataReader, ProductModel>();
return AutoMapper.Mapper.Map<IDataReader, IList<ProductModel>>(dr);
}
return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)