我创建的字符串类型的简单扩展方法:扩展方法where子句
public static bool Contains(this string word, string[] values)
{
foreach(string s in values)
{
if(!word.Contains(s))
return false;
}
return true;
}
现在
,我有一个LINQ查询,看起来像这样:
public static IEnumerable<ISearchable> Search(params string[] keywords)
{
XPQuery<Customer> customers = new XPQuery<Customer>(unitOfWork); // **
var found = from c in customers
where c.Notes.Contains(keywords)
select c;
return found.Cast<ISearchable>();
}
我在where子句中得到'方法不被支持'异常,如果我使用string.Contains方法,这将很好地工作。
我的扩展方法有什么问题,或者我试图在linq where子句中使用它吗?
** XPQuery是一个devexpress组件,因为这是我使用的ORM,它是它们的linq-to-xpo查询对象。
希望是让我的Contains(string [] s)方法感觉像string.Contains(string s)的重载。此外,我使用您提供的内容获得了相同的错误。似乎它可能是LINQ到XPO的问题,但我不知道如何确定。 – 2010-09-14 22:09:46