Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linq query for top 1

Posted on 2011-09-27
6
Medium Priority
?
243 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
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.

 
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

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!

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

636 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