范围变量隐藏封闭块LINQ中的变量



我有以下3个查询。第一个工作得很好,但第二个两个抛出了一个错误,说range varible Year (or semester, respectively) hides a variable in an enclosing block or a range variable previously defined in the query expression.我不擅长编码,所以我在MSDN上查找的任何东西都让我更加困惑。如果有任何帮助就太好了。

Dim compulsoryModule = (From mods In db.Modules
                                Join deg In db.Degrees On mods.Degree_code Equals deg.Degree_code
                                Where deg.Degree_code = degree And mods.Compulsory = True And mods.Level = 1
                                Select mods.Module_code)
        Dim year = (From mods1 In db.Modules
                    Join deg1 In db.Degrees On mods1.Degree_code Equals deg1.Degree_code
                    Where deg1.Degree_code = degree And mods1.Compulsory = True And mods1.Level = 1
                    Select mods1.Year)
        Dim semester = (From mods In db.Modules
                        Join deg In db.Degrees On mods.Degree_code Equals deg.Degree_code
                         Where deg.Degree_code = degree And mods.Compulsory = True And mods.Level = 1
                      Select mods.Semester)

错误仅在year查询中的select mods1.yearselect mods.semester NB行上抛出,数据库dims已更改为对它们具有1。我只是想解决这个问题。如果我删除它们,它不会改变代码

我将Dim年改为年,将Dim学期改为学期。这已经更正了错误

相关内容

  • 没有找到相关文章

最新更新