“If Any Contains Any” (DbExpressionBinding requires an input)

喜欢而已 提交于 2019-12-11 04:02:36

问题


I'm trying to build a simple search where I pass a list of keywords. But soon as I add the "any contains keywords" as a list instead of a string I get:

"DbExpressionBinding requires an input expression with a collection ResultType."

I have extended IQueryable<Inspector> with:

 public static IQueryable<Inspector> Search(this IQueryable<Inspector> qry, List<string> keywords)
 {
    return from i in qry
           where
             i.LastName.Any(x => keywords.Contains(i.LastName)) ||
             i.FirstName.Any(x => keywords.Contains(i.FirstName)) ||
             i.City.Any(x => keywords.Contains(i.City)) ||
           select i;
 }

And when I call it I use:

return qry.Search(keywords).ToList();

How should I fix this issue?


回答1:


I think you're trying to get at this:

return from i in qry
    where keywords.Contains(i.LastName) ||
        keywords.Contains(i.FirstName) ||  
        keywords.Contains(i.City)
    select i;

This will return you any records where the FirstName, LastName, or City is in your keyword list.



来源:https://stackoverflow.com/questions/15411651/if-any-contains-any-dbexpressionbinding-requires-an-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!