I'm trying to evaluate func<T, bool>
with EF.Functions.Like
in CSharpScript.EvaluateAsync
, But I have an error in run time (The name 'EF' does not exist in the current context) when call GetPredicate()
method.
Create Func Method:
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;
}
}
Call Method:
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);
How to do this?