1

I have the following code which is throwing an error on the submit line. It says that data type(s) of the type parameters ) in method cannot be inferred from these arguments. As I have (I think) explicitly stated the data types surely it should work. The userID is being taken directly from the database through another query.

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)

Dim take As New Take With _
            {.User_Number = userId, _
             .Degree_code = degree, _
             .Module_code = compulsoryModule, _
             .Year = years, _
             .Semester = semesters}

        db.Takes.InsertAllOnSubmit(take)

It is the last line that gives the error

4

1 回答 1

1

好的,解决了这个问题。问题是我返回了多条记录并尝试将它们作为一条新记录输入,从而导致错误。我将提交部分修改为我的代码的 for 循环,以遍历结果并单独添加它们。我使用的循环是:

 For Each moduleCode As String In compulsoryModules

            Dim take As New Take With _
                {.User_Number = userId, _
                 .Degree_code = degree, _
                 .Module_code = moduleCode, _
                 .Year = years, _
                 .Semester = semesters}

            db.Takes.InsertOnSubmit(take)

希望这对其他人有帮助。

于 2013-04-27T18:51:48.207 回答