c# - Linq 相当于 SQL 中的 '_'
问题描述
是否有从 SQL 中的“ _ ”到 Linq的等价物。
在 SQL 中,它就像一个空格,因此它选择所有内容并忽略此字符。
例如SELECT * FROM customers WHERE customers.ID LIKE '12431466_1'
,选择所有 ID 为 12431266 并在末尾为 1
解决方案
The answer depends on your specific needs:
If you're using linq-to-sql and would like it to run the query you posted, you can use the same string with SqlMethods.Like.
If you want to have a solution for linq-to-objects or a custom linq provider, you'll need to either use string methods running inside the C# runtime, like StartsWith
and EndsWith
or use Regext.IsMatch or something similar.
推荐阅读
- lua - 如何检查Lua中是否存在表子字段?
- python - 在 Python 中找到访问地理坐标的最有效路径
- c# - 需要从json中提取一些值
- python - 无法更改 Django 中的模型字段类型
- node.js - 2 个文档通过 Testroute 持续存在
- css - materializecss 搜索栏在 chrome 中无法正常工作
- javascript - 默认情况下,Javascript `fetch` 是否遵循重定向?
- r - 如何控制 mapview 包中的特定地图和图例颜色?
- c++ - 从函数参数中的临时值调用复制构造函数时
- cakephp-2.0 - 修改从关联模型返回结果的方式