1

我有一个表,其中有一个名为 COMMA_SEPARATED_VALUES 的字段。我怎样才能用一个单一的过滤器!(我必须将它集成到更大的查询中)LINQ 查询所有行,其中一个条目在整数范围内。

Table TEST
ID          COMMA_SEPARATED_VALUES
-----------------------------------
1           '1,2,3,4'
2           '1,5,100,4,33'
3           '666,999'
4           '5,55,5'

过滤范围“10 - 99”将导致

ID
------------------------
2           (because of 33)
4           (because of 55)
4

1 回答 1

2

如果您知道调用方法的性能副作用AsEnumerable()并且它没有害处:

int lowerBound = 10;  // lower bound of your range
int upperBound = 99;  // upper bound of your range

var d = from row in context.Test.AsEnumerable()
        let integers = row.COMMA_SEPERATED_VALUES
                          .Split(new char[] { ',' })
                          .Select(p => int.Parse(p))
        where integers.Any(p => p < upperBound && p > lowerBound)
        select row;
于 2013-10-09T11:46:07.093 回答