2011-11-22 137 views
1

錯誤我使用LINQPad來運行下面的查詢:LINQ到SQL查詢與StartsWith

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,WbsNumber開始WbsNumberProgramWbsNumbers如果有幫助。

enter image description here

回答

6

試試這個:

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

工作!謝謝。 –