0

When I write a code like below, I take this error message: "The query operator 'ElementAtOrDefault' is not supported."

How can I fix it?

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 

3 Answers 3

3

You haven't really queried yet. strViews isn't the result set, it is the query. You need to actually retrieve some data.

var chosen = strViews.FirstOrDefault(); 
Sign up to request clarification or add additional context in comments.

2 Comments

Good point about the late binding -- that can really mess you up if you're not careful.
Thanks, this sentence is very important: "strViews isn't the result set, it is the query."
3

Have you tried using the FirstOrDefault() then check to make sure it is not null. My VB syntax is probably suspect, but you get the idea.

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 

Comments

0

I am no expert in VB or LINQ2SQL but does this not have anything to do with the fact that you say strViews(0).MT_VIEWS while there is a chance that strViews can be null?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.