System.String []斯普利特(的char [])'方法无法识别 [英] System.String[] Split(Char[])' method unrecognized
问题描述
我有以下的数据,我想筛选使用LINQ to实体的数据,但我得到异常:
I have the following data and i want to filter the data using Linq to Entities, But i am getting the exception :
LINQ到实体无法识别方法'System.String []
分裂(字符[])'方法,和这种方法不能被翻译成
店前pression。
LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression.
我在表格下面的数据
1 HPM,BKM NULL 1,2,3
2 HPM,BKM L1,L2 1,2
3 KK,CC,ZZ,PP 3,4
和我写了下面的code
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();
应该给我值1,2,3作为我的结果。
It should be give me values 1,2,3 as my result.
推荐答案
这是因为没有办法斯普利特(字符[])转换成SQL前pression。您需要做了ToList()首先然后执行你的分割操作,但要注意,这将带回更多结果到您的计算机使用分体式前pression筛选出来之前:
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();
这篇关于System.String []斯普利特(的char [])'方法无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!