Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

linq query to return object with parameter

Posted on 2010-09-03
3
Medium Priority
?
389 Views
Last Modified: 2013-11-11
linq query to get highest id with datetime query

I need a linq query that returns a QuestionAnswer object with the datetimevalue given the previousAttemptID

Here is database table called "QuestionAnswers"


ID  (int)
previousAttemptID  (int)
userID (int)
questionID (int)
anwerID (int)
dateAnswered (datetime)



So something like



QuestionAnswer = db.QuestionAnswers.Where(r => r.previousAttemptID == previousAttemptID)  // then get the record with the max datetime stampe (field dateAnswered)







0
Comment
Question by:ToString1
[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
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 1336 total points
ID: 33596016
Try this:

QuestionAnswer = db.QuestionAnswers.Where(r => r.previousAttemptID == previousAttemptID).OrderBy(dateAnswered).First()
0
 
LVL 19

Assisted Solution

by:Bardobrave
Bardobrave earned 1336 total points
ID: 33596028
EDIT: As you want the max datetime you'll need to order by DESC

QuestionAnswer = db.QuestionAnswers.Where(r => r.previousAttemptID == previousAttemptID).OrderByDescending(dateAnswered).First()
0
 
LVL 5

Assisted Solution

by:tvPrasad
tvPrasad earned 664 total points
ID: 33596087
QuestionAnswer= db.QuestionAnswers.OrderByDescending(r => r.dateAnswered).Where(r => r.previousAttemptID == previousAttemptID).First();
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 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