LINQ:查询主体必须以select子句或group子句以及其他错误结束

时间:2012-06-13 15:42:21

标签: linq linq-to-sql

我有以下SQL语句:

CASE  
WHEN wt.pmtlr_oi IS NULL OR (SELECT COUNT(*) FROM mc.SCHEDENTRY WITH (NOLOCK) WHERE wt_oi = wt.wtskoi AND shedref_oi NOT IN (SELECT shdoi FROM mc.SCHDULE WITH (NOLOCK) WHERE aenm LIKE '%Breakin%')) = 0   AND wt.pmtlr_oi IS NULL     
THEN 'Break-In' 
ELSE 'Planned' 
END AS schedule

我已将其翻译成:

Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && shedref_oi !(from sc in SCHDULEs
    where sc.Aenm.Contains("Breakin") select sc.Shdoi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"}

以下是它在select语句中的显示方式:

select new {Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && shedref_oi !(from sc in SCHDULEs
    where sc.Aenm.Contains("Breakin") select sc.Shdoi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"}); 

然而,当我尝试运行它时,有些问题我不知道如何修复。第一个是编译器似乎不喜欢这里找到的NOT IN:

&& shedref_oi !(from sc in SCHDULEs

我得到一个“查询正文必须以select子句或group子句结束”错误。

编译器也不喜欢这样:

select sc.Shdoi)).Count() == 0

在外括号中,我收到“语法错误”,“预期”错误,并且在此期间收到“语句预期”错误消息。

我很感激帮助您解决此问题。

编辑:

好的,在评论之后我更正了LINQ语句,如下所示:

select new {Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && !(from sc in SCHDULEs
    where sc.Aenm.Contains("Breakin") select sc.Shdoi).Contains(shedref_oi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"}); 

并且编译器喜欢它。但是,它仍然不喜欢.Count()。我收到“声明预期”错误。使用.Count()进行sql SELECT COUNT(*)?

是不正确的

0 个答案:

没有答案
相关问题