C# 转换IEnumerable<;达佩罗>;到IEnumerable<;T>;在动态整洁的查询中

C# 转换IEnumerable<;达佩罗>;到IEnumerable<;T>;在动态整洁的查询中,c#,dynamic,automapper,dapper,C#,Dynamic,Automapper,Dapper,我试图转换dapper动态查询返回的IEnumerable,我不在dapper中使用查询,因为我返回的是另一列,而我的模型中没有该列,所以在获得该列(分页中的总计数)后,我希望返回一个类型化列表 我试过使用AutoMapper,但它不起作用 代码如下: IEnumerable<dynamic> result; using (var conn = new SqlConnection(connectionString)) { conn.Open(); result =

我试图转换dapper动态查询返回的IEnumerable,我不在dapper中使用查询,因为我返回的是另一列,而我的模型中没有该列,所以在获得该列(分页中的总计数)后,我希望返回一个类型化列表

我试过使用AutoMapper,但它不起作用

代码如下:

IEnumerable<dynamic> result;

using (var conn = new SqlConnection(connectionString))
{
    conn.Open();
    result = conn.Query<dynamic>(spName, p, commandType: CommandType.StoredProcedure);
}

totalCount = result.First().total_count;
//return Mapper.DynamicMap<List<T>>(result); //Empty result
//return Mapper.Map<IEnumerable<dynamic>, List<T>>(result); //Error
return result.Select(r => (T)Mapper.DynamicMap<T>(r)).ToList(); //Empty objects
i可数结果;
使用(var conn=newsqlconnection(connectionString))
{
conn.Open();
结果=conn.Query(spName,p,commandType:commandType.StoredProcess);
}
totalCount=result.First().total\u count;
//返回Mapper.DynamicMap(结果)//空结果
//返回Mapper.Map(结果)//错误
返回result.Select(r=>(T)Mapper.DynamicMap(r)).ToList()//空对象

如何将动态整洁的结果转换为键入的列表?

结果是否包含您期望的结果?什么是
T
?如何在AutoMapper中配置到
T
的动态映射?据我所知,DynamicMap不需要在AutoMapper中预先配置。T是一个类,这是一个泛型方法,我在所有模型中使用它,查询返回模型中的所有属性,还有一个模型不包含的额外列,它是数据集中的行总数