Solved

Linq to select select top 1

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

20 Experts available now in Live!

Get 1:1 Help Now