C# SqlMethods 喜欢不工作

标签 c# linq

我是 Linq 的新手,无法使用 SqlMethods.Like 函数。

这是我的简化示例:

        List<string> mylist = new List<string>();
        mylist.Add("100");
        mylist.Add("101");
        mylist.Add("102");
        mylist.Add("103");
        mylist.Add("104");
        mylist.Add("105");
        mylist.Add("106");
        mylist.Add("107");

        var filtered = mylist.Where(x => SqlMethods.Like(x, "10%"));
        foreach (var record in filtered)
        {
            textBox1.Text += record + "\n";
        }

我的名为 filtered 的变量返回为空。我错过了什么?

如果我使用 x.Equals("100") 我会返回结果。

最佳答案

SqlMethods.Like

Determines whether a specific character string matches a specified pattern. This method is currently only supported in LINQ to SQL queries.

您的查询不是 LINQ to SQL 查询。

关于C# SqlMethods 喜欢不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12805467/

相关文章:

c# - 如何在 Mac OS X 上的 VSCode 项目中包含 'System.Runtime.Serialization.Json' 命名空间?

c# - 如何使用 Linq 获取不在某个时间段内的前两个连续日期时间点?

c# - LINQ 不同查询

c# - 将 SQL 查询转换为 C#

c# - 为什么 wpf UpdateSourceTrigger 没有明确绑定(bind)?

c# - 使用 WCF OperationContext 通过 Channel 传递 header 值

具有相同方法名称的 C# 接口(interface)

c# - .NET 中具有深度继承的类的内存分配

c# - 使用 Linq 从列表中获取所有匹配值的索引

Linq 与 sum 相交