Solved

Linq to select select top 1

Posted on 2013-11-20
1
446 Views
Last Modified: 2016-02-10
I need to get a row from my gneic list where the BusDate is less than a variable date.
The qualifying date should be the max date returned, instead I get the lowest date that qualifies to be less than s.BusDte
I tried first or default

SomeObject s

var result = (from q in list
                                   where q.ID.ToString() == s.ID && q.BusDate <= s.BusDate
                                   select q.Total).Take(1).LastOrDefault();
0
Comment
Question by:countrymeister
[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
1 Comment
 
LVL 11

Accepted Solution

by:
jasonduan earned 500 total points
ID: 39663477
try this:

var result = (from q in list
                    where q.ID.ToString() == s.ID && q.BusDate <= s.BusDate
                    orderby q.BusDate descending
                    select q.Total).FirstOrDefault();
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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