我使用RegEx删除LINQ查询中的HTML标记,但引发了以下错误:
方法
'System.String Replace(System.String, System.String, System.String)'
作为SQL不支持执行。
Help helpDBSession = new Help();
IEnumerable<Article> articles = null;
if (lang.ToLower() == "en")
{
articles = helpDBSession.Articles.Where(artilce => artilce.NameEn.Contains(searchPattern) ||
System.Text.RegularExpressions.Regex.Replace(artilce.ContentEn, "<(.|\n)*?>",String.Empty).Contains(searchPattern));
}
else
{
articles = helpDBSession.Articles.Where(artilce => artilce.NameAr.Contains(searchPattern) ||
System.Text.RegularExpressions.Regex.Replace(artilce.ContentAr, "<(.|\n)*?>", String.Empty).Contains(searchPattern));
}
if (articles != null && articles.Count() > 0)
{
return articles.ToList();
}
发布于 2010-07-10 05:32:01
发布于 2010-07-10 05:55:33
根据错误消息,我假设LINQ无法翻译LINQ语句的RegEx部分,因为SQLServer不支持RegEx。
你必须:
例如:
Help helpDBSession = new Help();
IEnumerable<Article> articles = null;
if (lang.ToLower() == "en")
{
articles = helpDBSession.Articles.Where(
artilce => artilce.NameEn.Contains(searchPattern)
)
}
else
{
articles = helpDBSession.Articles.Where(
artilce => artilce.NameAr.Contains(searchPattern)
)
}
if (articles != null && articles.Count() > 0)
{
if (lang.ToLower() == "en")
{
return articles.ToList().Where(
artilce => System.Text.RegularExpressions.Regex.Replace(
artilce.ContentEn,
"<(.|\n)*?>",String.Empty).Contains(searchPattern)
)
);
}
else
{
return articles.ToList().Where(
artilce => System.Text.RegularExpressions.Regex.Replace(
artilce.ContentAr,
"<(.|\n)*?>",String.Empty).Contains(searchPattern)
)
);
}
}
https://stackoverflow.com/questions/3219349
复制相似问题