Mike Fielden
Mike Fielden

Reputation: 10153

Linq-to-sql query error with StartsWith

I am using LINQPad to run the following query:

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();

And I get the error:

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

I'm not sure how to go about correcting this error. I need to get each Program where the WbsNumber starts with the WbsNumber contained within ProgramWbsNumbers if that helps.

enter image description here

Upvotes: 2

Views: 961

Answers (1)

Magnus
Magnus

Reputation: 46929

Try this:

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

Upvotes: 8

Related Questions