使用StartsWith进行Linq-to-sql查询错误

时间:2011-11-22 19:26:07

标签: 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:String.StartsWith方法仅支持可在客户端上计算的参数。

我不确定如何纠正此错误。如果有帮助的话,我需要将Program的{​​{1}}开始于WbsNumber中包含的WbsNumber。{/ p>

enter image description here

1 个答案:

答案 0 :(得分:8)

试试这个:

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