Solved

Linq to select select top 1

Posted on 2013-11-20
1
443 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
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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