【发布时间】:2014-05-29 09:16:39
【问题描述】:
我正在尝试实现一种方法,其中存储在数据库中的活动关键字(用逗号分隔)与用逗号分隔的给定字符串匹配。
public List<TblActivities> SearchByMultipleKeyword(string keywords)
{
string[] keyword = keywords.Split(',');
var results = (from a in Entities.TblActivities
where a.Keywords.Split(',').Any(p => keyword.Contains(p))
select a).ToList();
return results;
}
我收到以下错误:
LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method,
and this method cannot be translated into a store expression.
【问题讨论】:
-
错误表明您不能使用这些函数,因为它们不可用(这些函数和 TSQL 之间没有完成映射)更好的选择可能是使用 context.ExecuteStoreQuery 你可以自己写SQL
-
你看过右边的相关问题了吗?粗略一瞥表明您会很快找到答案...
-
@3dd 不能再反对你了。正确的选择是实际规范化数据库,以便您可以实际使用 SQL、索引和表统计信息。否则,使用 RDBMS 有什么意义。如果您真的想这样做 CSV gubbins,请改用无模式数据库!
-
@Aron 不一定正确,我们不知道关键字列的上下文,它可能无法规范化,但我同意,如果规范化会更好