我有以下代码:
Dim getProspect = (From p In dbContext.IRF_Prospects _
Where p.url = prospect_url _
Select p).FirstOrDefault
' If they have a record...
If Not IsDBNull(getProspect) Then
If IsDBNull(getProspect.user_id) Then
' Prepopulate the form with their information.
txtFirst.Text = getProspect.first_name
Else
' Redirect them to login.
Response.Redirect("login.aspx")
End If
当我执行它时,它会抛出一个未设置为对象错误实例的对象引用getProspect.user_id
。为什么要这样做?我IsDBNull
首先验证它是否存在的事实不应该防止这种情况发生吗?