gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:37:20 30 4
gpt4 key购买 nike

我正在使用 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com