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();

I have written the above piece of code to extract a list whose name starts with the Search element in textbox...then I need to exclude the names who have already enrolled for the course, then if they are not the students of the Institution (M => M.T_Tln_Student == null) and ex-students include in the list..

But I am getting Null reference exception occurred...

4

2 回答 2

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();

重点是使用这种技术来拆分事物。

于 2013-10-08T13:32:53.310 回答
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)

我建议您在此处开始搜索 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)
于 2013-10-08T13:30:28.630 回答