我一直在尝试使用AutoMapper读取单个Record。但是我无法使用下面的代码
public ChartOfAccount GetSingleCOA( )
{
string queryString = "select * from ChartofAccounts where AccNo=423";
using (var connection = new SqlConnection(conStr))
using (var command = new SqlCommand(queryString, connection))
{
connection.Open();
using (var reader = command.ExecuteReader())
if (reader.HasRows)
{
reader.Read();
return Mapper.Map<IDataRecord, ChartOfAccount>(reader);
}
}
return null;
}
答案 0 :(得分:1)
只需将行更改为
return Mapper.DynamicMap<IDataReader, ChartOfAccount>(reader);
解决了问题