internal IEnumerable<Setting> Search(string text)
{
Func<string, string, bool> searchCI =
(x, y) => x.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0;
return _dc.Settings.Where(
x => searchCI(x.key, text)
|| searchCI(x.description, text) );
}
此代码生成异常:{"Method 'System.Object DynamicInvoke(System.Object[])' has no supported translation to SQL."}
帮助修复,请
升级版:
internal IEnumerable<Setting> Search(string text)
{
return _dc.Settings.Where(
x => x.key.IndexOf(text).StringComparison.OrdinalIgnoreCase) >= 0
|| x.description.IndexOf(text).StringComparison.OrdinalIgnoreCase) >= 0;
}
这有效,但重复代码。我怎样才能使子表达式可以编译为 sql(如果可能)?