?
Solved

Linq query for top 1

Posted on 2011-09-27
6
Medium Priority
?
240 Views
Last Modified: 2012-05-12
i am trying to retrieve the top 1 object from the following query but it is not working as expected. Please help.
Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Take 1 Select q)

Open in new window

0
Comment
Question by:suroma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36709400
Try this


Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Select q).Take(1)
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36709426
Sorry it was c# syntax.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36709498
give us your definition of qu
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 36709554
Actually, you probably do not need to define that.
Take 1 means you are looking for and up to position 1, just use .First instead, e.g
Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Select q).First

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36709744
Also your Question has to implement IComparable
0
 

Author Closing Comment

by:suroma
ID: 36715055
Works perfectly. Many thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question