Solved

Linq to select select top 1

Posted on 2013-11-20
1
434 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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

10 Experts available now in Live!

Get 1:1 Help Now