2013-10-08 39 views
-1
string search = textBoxNachname.Text; 
var Liste = _db.T_Subscribers 
       .Where(x => x.firstname.StartsWith(search)) 
       .Except(_selectedcourse.T_Coursedetail.Select(b => b.T_Subscribers)) 
       .Where(M => M.T_Tln_Student == null || M.T_Tln_Stud.Status.T_Status.T_Statusart == _studentEx).ToList(); 

我寫了上面這段代碼來提取名稱以文本框中的搜索元素開頭的列表...然後我需要排除已經註冊了課程的名稱,然後如果它們不是學會(M => M.T_Tln_Student == null)和以前的學生的學生包括在列表..如何在linq中調試`空引用異常發生`?

但我正在逐漸發生空引用異常......

+1

你有沒有試過在表達式中插入一個斷點來查看什麼是空?對此的任何答案只能猜測... –

+0

拆分linq語句,看看哪一個拋出異常 –

+1

你不能在linq查詢中添加斷點。你得到的錯誤意味着你的一個參數爲空。 –

回答

0

看看這個行:

.Where(M => M.T_Tln_Student == null || 
      M.T_Tln_Stud    // might be null 
         .Status  // might be null 
         .T_Status // might be null 
         .T_Statusart // might be null 
          == _studentEx) 

我會sugge ST,你開始尋找您的NullReferenceException這裏

.Where(M => M.T_Tln_Student == null || 
      M.T_Tln_Stud == null || 
      M.T_Tln_Stud.Status == null|| 
      M.T_Tln_Stud.Status.T_Status == null || 
      M.T_Tln_Stud.Status.T_Status.T_Statusart == null || 
      M.T_Tln_Stud.Status.T_Status.T_Statusart == _studentEx) 
4

這是你如何調試此:

var Liste1 = _db.T_Subscribers.Where(x => x.firstname.StartsWith(search)); 
var Liste2 = Liste1.Except(
       _selectedcourse.T_Coursedetail.Select(b => b.T_Subscribers)); 
var Liste3 = Liste2.Where(M => 
       M.T_Tln_Student == null || 
       M.T_Tln_Stud.Status.T_Status.T_Statusart == _studentEx); 
var Liste = Liste3.ToList(); 

重點是使用這種技術來拆分的事情。

相關問題