映射表达式

时间:2019-03-29 10:05:15

标签: c# .net-core odata automapper

我很难为DataServiceQuery映射表达式。

我的输入如下:Expression<Func<TEntity, bool>> predicatestring entitySet

我现在需要将其转换为Expression<Func<TOutput, bool>> output

我当前正在使用AutoMapper,并在TEntityTOutput之间创建了一个Map,然后尝试通过以下方式映射Expression:

var type = Type.GetType($"ServiceContext.{entitySet}, ServiceContext");
var predicateTargetType = typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(type, typeof(bool)));
var mappedPredicate = _mapper.Map(predicate, predicate.GetType(), predicateTargetType);

上面的代码似乎好像在工作,在运行时它执行了,但是问题是,每当我使用mappedPredicate变量时,它都会引发以下异常:

  

System.InvalidOperationException:代码应该无法访问

调用此代码的层对TOutput一无所知,所以我只有TOutput的名称(字符串格式)和TEntity的表达式。

任何帮助将非常感谢!

0 个答案:

没有答案