sql - StartsWith 的 Linq-to-sql 查询错误

标签 sql linq linq-to-sql

我正在使用 LINQPad 运行以下查询:

var pds = (from p in Projects
            group p by p.FiscalYearVariables.FiscalYear into grouped
            where grouped.Count() > 0
            select new { 
                fiscalYear = grouped.Key,
                projectDetails = grouped.SelectMany(a=>a.ProjectDetails),
                Programs = (from pwbs in Programs.SelectMany(a =>a.ProgramWbsNumbers)
                            let ds = pwbs.WbsNumbers.DisplayString
                            where pwbs.Programs.IsActive
                            && (from w in WbsNumbers
                                where w.DisplayString.StartsWith(ds)
                                select w).Any()
                            select pwbs.Programs)
            });

            pds.Dump();

我得到了错误:

NotSupportedException: Only arguments that can be evaluated on the client are supported for the String.StartsWith method.

我不确定如何纠正这个错误。如果有帮助,我需要获取每个 Program,其中 WbsNumberProgramWbsNumbers 中包含的 WbsNumber 开头。

enter image description here

最佳答案

试试这个:

where SqlMethods.Like(w.DisplayString, ds + "%")

关于sql - StartsWith 的 Linq-to-sql 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232569/

相关文章:

sql - MySQL 使用 REGEX 匹配逗号分隔值中是否存在术语

php - 如何在SQL查询中搜索不精确的关键字

mysql - 如何保留存在同一关系的多个实例的关联表?

php - 带有 LinQ 过滤器和 jQuery tmpl 示例的 jQuery AJAX 请求

c# - == 默认情况下在 c# linq 中不区分大小写

php - 我需要一个 mysql group by query 以在每个员工的一行中从每个员工的日期时间列返回每小时条目

c# - NHibernate 3.1 与 Linq 的迁移问题

c# - 返回 Enumerable.Empty<T>().AsQueryable() 是个坏主意吗?

c# - 如何忽略linq to sql中违反主键约束

c# - 如何使用 ext.net 在 asp.net c# 中创建 Crystal 报表?