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查询中的“只能从没有参数的简单或限定名称推断范围变量名”错误_Linq_Linq To Entities - Fatal编程技术网

linq查询中的“只能从没有参数的简单或限定名称推断范围变量名”错误

linq查询中的“只能从没有参数的简单或限定名称推断范围变量名”错误,linq,linq-to-entities,Linq,Linq To Entities,我试图在LinqPad中运行以下查询,第10行不断出现上述错误 From c in Courses Where c.CourseID = 212 From cc in c.CourseContents Where cc.Active And Not cc.Deleted Order By cc.OrderIndex Group cc by c Into Content = Group Select New With { c, .Content = From cc in Conte

我试图在LinqPad中运行以下查询,第10行不断出现上述错误

From c in Courses Where c.CourseID = 212
From cc in c.CourseContents Where cc.Active And Not cc.Deleted Order By cc.OrderIndex
Group cc by c Into Content = Group
Select New With {
    c,
    .Content = From cc in Content Select New With {
        .id = cc.CourseContentID,
        .content = If(cc.ContentTypeID = 1, 
        from a in Assessments Where a.AssessmentID = cc.ContentID select a, 
        If (cc.ContentTypeID = 2, from cf in CourseFiles Where cf.CourseFileID = cc.ContentID select cf,
        from ct in CourseTexts Where ct.CourseTextID = cc.ContentID select ct))     
    }
}
我尝试添加select foo=cf,但没有帮助


我如何解决这个问题?

我刚刚遇到了这个问题,我想看看是否有任何悬而未决的问题需要回答

解决问题的方法是:

If (cc.ContentTypeID = 2, from cf in CourseFiles Where cf.CourseFileID = cc.ContentID select cf,
If (cc.ContentTypeID = 2, (from cf in CourseFiles Where cf.CourseFileID = cc.ContentID select cf),
发生的事情是最后一个逗号不明确。可以选择多个项目,如选择x、y、z,…,这样最后一个逗号就可以这样解释,需要另一个标识符。要解决此问题,请在整个From…Select语句周围加上括号

像这样: