1

私は1つのテーブルを持っています。

列名が branch の 1 つがあります。コンマ区切りの値が含まれています。このような

1,2
2,4
5,6
3,4
6,8
4,9,7

等々...

そして、List<string> 2 つの値 3 と 4 を含むものがあります。

3 または 4 を含むすべての列データを取得するデータベース クエリが必要です。

したがって、アウトプットは

2,4
3,4
4,9,7

そして、私はこのコードを解決策として使用しています。

RowCollection.Where(row => row.Split(",").ToList()
           .Where(x => list.Contains(x)).Any()).ToList(); 

そして、これはエラーを示しています。

Method 'System.String[] Split(Char[])' has no supported translation to SQL.

私はこれのために何をすべきか解決策を教えてください。

4

1 に答える 1

2

Unfortunately its the IQueryable you are using (Linq to SQL) that is not supporting the Split function.

You are really only left with the IEnumerable (Linq to Objects) support for it in this case. You second code snippet is what you need to do, or something like...

well in this case try out liek this

var collection = RowCollection.ToList();

var filterdate = collection.Where(row => row.Split(",").ToList()
                    .Where(x => list.Contains(x)).Any()).ToList();

as split is not supported n t-sql you should first fetch data in one list and than apply your condition.

or apply AsEnumerable()

var collection = RowCollection.AsEnumerable()
                  .Where(row => row.Split(",").ToList()
                        .Where(x => list.Contains(x)).Any()).ToList();
于 2012-12-06T10:07:08.897 に答える