我使用automapper 把Expression<Func<TDto, IEnumerable<C>>> 转<Expression<Func<TEntity, IEnumerable<C>>> 报 System.InvalidCastException: 无法将类型为“System.Linq.Expressions.Expression`1[System.Func`2[meixiaohu.Entities.MongoDB.Order,System.Collections.Generic.List`1[meixiaohu.Entities.MongoDB.ChildOrder]]]”的对象强制转换为类型“System.Linq.Expressions.Expression`1[System.Func`2[meixiaohu.Entities.MongoDB.Order,System.Collections.Generic.IEnumerable`1
转换代码
public async virtual Task Pull<C>(string id, Expression<Func<TDto, IEnumerable<C>>> field, Expression<Func<C, bool>> expression)
{
var entityField = Mapper.Map<Expression<Func<TEntity, IEnumerable<C>>>>(field);
}
Expression是表达式树解析成SQL的,Fun是泛型委托,你最终的实际结果应该是IEnumerable