LINQ to Entities无法识别方法'System.String [] Split(Char [])'方法, [英] LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method,

查看:109
本文介绍了LINQ to Entities无法识别方法'System.String [] Split(Char [])'方法,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一种方法,该方法存储在数据库中用于活动(用逗号分隔)的关键字与用逗号分隔的给定字符串匹配.

I am trying to implement a method where the keywords stored in the database for an activity (split by a comma) match the giving string split by a comma.

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.

推荐答案

对于不涉及太多关键字和太多行的查询,您可以实现此简单而快速的解决方案.您可以按以下步骤反复细化结果,轻松解决Split函数:

For queries that do not involve too many keywords and too many rows you could implement this simple and quick solution. You can easily get around the Split function by repeatedly refining your results as follows:

 public List<TblActivities> SearchByMultipleKeyword(string keywords)
 {
     string[] keywords = pKeywords.Split(',');

     var results = Entities.TblActivities.AsQueryable();    

     foreach(string k in keywords){

         results  = from a in results
                    where a.Keywords.Contains(k)
                    select a;
     }
     return results.ToList();
 }

这篇关于LINQ to Entities无法识别方法'System.String [] Split(Char [])'方法,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆