LINQ Query based on user preferences
Posted
by Chris Phelps
on Stack Overflow
See other posts from Stack Overflow
or by Chris Phelps
Published on 2010-05-12T00:08:12Z
Indexed on
2010/05/12
0:14 UTC
Read the original article
Hit count: 156
How can I do this better (so it actually works : )
I have a LINQ Query that includes an order by that is based on a user preference. The user can decide if they would like the results ordered asc or desc.
If fuserclass.SortOrder = "Ascending" Then
Dim mydat = (From c In dc.ITRS Order By c.Date Ascending Select c)
Else
Dim mydat = (From c In dc.ITRS Order By c.Date Descending Select c)
End If
For each mydata in mydat ***<<<error "mydat is not declared"***
I know I could put my For Each loop inside the If and Else, but that seems silly to have the same code twice. I know you know of a better way : )
© Stack Overflow or respective owner