So you are looking for a value (from the query-string) in a space-delimited column in the database? And you're using Split
to query the individual values inside the database?
(just checking my assumptions...)
string.Split
is not supported in this way (at the database on column data) - see here for the supported string operations. (note that string.Split
is explicitly not supported).
I'm lazy; when I delimit data in the database (relatively rare), I always add the same delimiter to the start and end of the data; then I can just search for:
string searchFor = DELIMITER + searchValue + DELIMITER;
...
.Where(row => row.Value.Contains(searchFor));
However; in this case, I expect the most practical option might be to write a UDF function that searches a delimited varchar
(correctly handling the first/last item), and expose the UDF on the data-context - then use:
.Where(row => ctx.ContainsValue(row.Value, searchValue)); // ContainsValue is our UDF
Or - normalise the data...
.Where(row => row.Values.Any(s=>s.Value == searchValue));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…