类型'System.String []'不支持比较运算符

编程入门 行业动态 更新时间:2024-10-28 10:32:22
本文介绍了类型'System.String []'不支持比较运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么这行:

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.

推荐答案

所以你正在寻找一个空格分隔的值(从查询字符串)列在数据库中?而您正在使用 Split 来查询数据库中的各个值?

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 []'不支持比较运算符

本文发布于:2023-10-30 12:21:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   运算符   类型   System   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!