System.String[] Split(Char[])' method unrecognized

匿名 (未验证) 提交于 2019-12-03 00:53:01

问题:

I have the following data and i want to filter the data using Linq to Entities, But i am getting the exception :

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

I have following data in the table

1           HPM,BKM     NULL        1,2,3 2           HPM,BKM     L1,L2       1,2 3           KK,CC,ZZ,PP             3,4 

And i am writing the following code

var criteria_1="1";  var criteria_2="HPM,"  var Col4 = DB.Letter_Logic.Where(m => m.Col1.Equals(criteria_1)             && m.Col2.Split(',').Contains(criteria_2)).ToList(); 

It should be give me values 1,2,3 as my result.

回答1:

This is because there is no way to translate Split(Char[]) into a SQL expression. You would need to do a ToList() first then perform your split operation, but beware that this will bring back more results to your computer before filtering them out using your split expression:

var Col4 = DB.Letter_Logic.Where(m => m.Col1.Equals(criteria_1))                           .ToList()                           .Where(m => m.Col2.Split(',').Contains(criteria_2))                           .ToList(); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!