Solved

linq query to return object with parameter

Posted on 2010-09-03
3
382 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
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 334 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 334 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 166 total points
ID: 33596087
QuestionAnswer= db.QuestionAnswers.OrderByDescending(r => r.dateAnswered).Where(r => r.previousAttemptID == previousAttemptID).First();
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now