首页 > 解决方案 > Linq 相当于 SQL 中的 '_'

问题描述

是否有从 SQL 中的“ _ ”到 Linq的等价物。

在 SQL 中,它就像一个空格,因此它选择所有内容并忽略此字符。

例如SELECT * FROM customers WHERE customers.ID LIKE '12431466_1',选择所有 ID 为 12431266 并在末尾为 1

标签: c#linq

解决方案


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.


推荐阅读