为什么这行:
var category = _dataContext.Categories.Where<Category>(p => p.Keywords.Split(' ').Contains<string>(context.Request.QueryString["q"])).First();
抛出System.NotSupportedException:
throws an System.NotSupportedException:
比较运营商不支持的类型'System.String []'
Comparison operators not supported for type 'System.String[]'
我该如何解决? 感谢。
And how can I fix it? Thanks.
推荐答案所以,你正在寻找一个值(从查询字符串)在数据库列?而你使用拆分来查询数据库里的个人价值?
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 不是以这种方式支持(在上列数据的数据库) - 在这里看到对于支持字符串操作。 (请注意, string.Split 终止的明确的不支持)。
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));
不过,在这种情况下,我希望最实际的选择可能是写一个UDF功能,搜索分隔的 VARCHAR (正确处理第一个/最后一个项目),并露出UDF上数据上下文 - 然后使用:
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));更多推荐
不支持的类型比较运算'System.String []'
发布评论