假设我有几个这样的课程:
public class QueryDetail
{
public string Name { get; set; }
public Expression<Func<MyObject, object>> IdToMapOn { get; set; }
}
public class MyObject
{
public string FooId { get; set; }
public string BarId { get; set; }
}
如何过滤以下查询:
(f, l) =>
{
return f.RecordCollection.Select(l.IdToMapOn); // how do I use that expression?
}
f.RecordCollection
是IEnumerable
MyObject
l
是QueryDetail
答案 0 :(得分:1)
需要编译表达式。见Expression Class
(f, l) =>
{
var compiled = l.IdToMapOn.Compile();
return f.RecordCollection.Select(compiled.Invoke);
}