当我编写如下代码时,我会收到以下错误消息:“不支持查询运算符'ElementAtOrDefault'。”
我该如何解决?
Dim tmpQuestion As New UIData
Dim strViews = From t In tmpQuestion.LU_QUESTIONs _
Where t.ID_QUESTION = Request.QueryString("IdQuestion") _
Select t
Dim mtViews = strViews(0).MT_VIEWS
答案 0 :(得分:3)
您是否尝试过使用FirstOrDefault(),然后检查以确保它不为空。我的VB语法可能很可疑,但你明白了。
Dim strView = (From t In tmpQuestion.LU_QUESTIONS _
Where t.ID_QUESTION = Request.QueryString("IdQuestion") _
Select t).FirstOrDefault()
Dim mtViews as ...
If Not strView Is Nothing
mtViews = strView.MT_VIEWS
EndIf
答案 1 :(得分:3)
你还没有真正质疑过。 strViews不是结果集, 是 查询。您需要实际检索一些数据。
var chosen = strViews.FirstOrDefault();
答案 2 :(得分:0)
我不是VB或LINQ2SQL的专家,但这与你说strViews(0).MT_VIEWS这个事实没有任何关系,而strViews有可能是null吗?