【发布时间】:2019-04-08 14:09:46
【问题描述】:
我正在尝试在CSharpScript.EvaluateAsync 中使用EF.Functions.Like 评估func<T, bool>,但是在调用GetPredicate() 方法时,运行时出现错误(当前上下文中不存在名称'EF')。
创建函数方法:
public static class Helper
{
public static async Task<Func<T, bool>> GetPredicate<T>(string stringExpression)
{
ScriptOptions options = ScriptOptions.Default.AddReferences(references: typeof(T).Assembly);
Func<T, bool> discountFilterExpression = await CSharpScript.EvaluateAsync<Func<T, bool>>(stringExpression, options);
return discountFilterExpression;
}
}
调用方法:
string expString = "x => EF.Functions.Like(x.CodeId, pattern) || EF.Functions.Like(x.Name, pattern) || EF.Functions.Like(x.CategoryId, pattern)";
Func<MyClass, bool> exp = await Helper.GetPredicate<MyClass>(expString);
如何做到这一点?
【问题讨论】:
标签: c# entity-framework-core roslyn func csharpscript