2013-04-27 91 views
1

我有以下代碼在提交行上拋出一個錯誤。它說那data type(s) of the type parameters) in method cannot be inferred from these arguments。正如我(我認爲)明確說明數據類型肯定應該起作用。 userID通過另一個查詢直接從數據庫中取出。類型參數的數據類型)在方法中不能從這些參數推斷

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) 

它是給出了錯誤

回答

1

好的解決了這個問題的最後一行。問題是我返回多個記錄並試圖將它們作爲一個新記錄輸入,導致錯誤。我將我的提交部分修改爲我的代碼的循環,以遍歷結果並單獨添加它們。我使用的循環是:

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) 

希望這可以幫助別人。

相關問題