分割字符串使用LINQ [英] Split string with LINQ

查看:752
本文介绍了分割字符串使用LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的结果订购的比赛中我的串线数。

因此​​,这里是code

  .ThenByDescending(P => p.Title.ToLower()
                              。分裂(' ')
                              .Count之间(瓦特=> words.Any(w.Contains)));
 

但它给我的错误,并说LINQ无法解析分割成SQL。

  

LINQ到实体不能识别方法'System.String []   分裂(字符[])'方法,和这种方法不能被翻译成   店内EX pression。

我如何通过LINQ实现拆分?

例如,对于这个阵列必须以这种方式顺序

 字= {A,AB}

AB一ggaaag GH // 3场比赛
BA AB GGT // 2场比赛
DD // 0匹配
 

解决方案

这意味着LINQ到实体未能找到可以写为SQL查询拆分方法转换。如果您要执行拆分功能,你必须通过调用把记录在内存了ToList() AsEnumerable()等等。

  VAR的结果=(从吨db.Table
              选择T).AsEnumerable()排序依据(X => x.Column).ThenByDescending(P => p.Title.ToLower.Split('')....);
 

I want to order by my results with the matches count in my string line.

So here is code

.ThenByDescending(p => p.Title.ToLower()
                              .Split(' ')
                              .Count(w => words.Any(w.Contains)));

But it bring me error and says that LINQ can't parse Split into SQL.

LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression.

How can I implement Split via LINQ?

For example, for this array it must order in this way

words = { "a", "ab" }

ab a ggaaag gh //3 matches
ba ab ggt //2 matches
dd //0 matches

解决方案

it means that Linq to entities failed to find translation of split method that can be written as sql query. if you want to perform split functions you have to bring the record in memory by calling ToList(), AsEnumerable() etc.

var result = (from t in db.Table
              select t).AsEnumerable().OrderBy(x=>x.Column).ThenByDescending(p=>p.Title.ToLower.Split(' ')....);

这篇关于分割字符串使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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