类型“System.String[]"不支持比较运算符
- 作者: 我只想好好睡一觉
- 来源: 51数据库
- 2022-12-08
问题描述
为什么是这条线:
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[]'
我该如何解决?谢谢.
推荐答案
所以您正在数据库中以空格分隔的列中寻找值(来自查询字符串)?并且您正在使用 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));
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
