Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LINQ:查询主体必须以select子句或group子句和其他错误结尾_Linq_Linq To Sql - Fatal编程技术网

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

LINQ:查询主体必须以select子句或group子句和其他错误结尾,linq,linq-to-sql,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

我有以下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
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"}); 
我把它翻译成:

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语句中的外观:

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
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"}); 
然而,当我尝试运行它时,有一些问题我不知道如何解决。第一个问题是编译器似乎不喜欢此处未找到的:

&& shedref_oi !(from sc in SCHDULEs
我得到一个“查询体必须以select子句或group子句结尾”错误

编译器也不喜欢这样:

select sc.Shdoi)).Count() == 0
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"}); 
在外圆括号中,我得到一个“语法错误”,“预期”错误,在句点上,我得到一个“语句预期”错误消息

如果您能帮我解决这个问题,我将不胜感激

编辑:

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

select sc.Shdoi)).Count() == 0
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()。我得到一个“语句预期”错误。我对sql SELECT Count(*)使用.Count()是否不正确?

&&shedref\u oi!(来自Schedules中的sc
:这里有一个语法错误,
运算符是一元的,所以
x!y
什么都没有。@ThomasLevesque我对此感到困惑。为什么在Mark Russo的例子中这里它什么都没有意味着没有:。我认为!运算符相当于sql,而不是你想要的
!(在SCH.Aenm.Contains(“Breakin”)的时间表中,从sc中选择sc.Shdoi.Contains(shedref_oi)
-将
应用于
Contains
@Rawling的结果,该结果消除了计数时的两个错误()方法,但编译器仍然不喜欢!运算符。但是,我现在在Mark Russo的博客上看到了!运算符和Contains()之间的关系。我没有看到它们一起工作。谢谢。如果我将!运算符放在sc.Aenm.Contains(“Breakin”)前面,请选择sc.Shdoi.Contains(shedref_oi)编译器将接受它,而不是括号中的fromt。然而,这与sql语句不一样吗?