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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With