Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 306
papapbpb Avatar asked Nov 27 '12 01:11

papapbpb


1 Answers

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();
like image 90
armen.shimoon Avatar answered Oct 21 '22 20:10

armen.shimoon