troubleshooting Question

ROW_NUMBER , LEFT OUTER JOIN in LINQ

Avatar of countrymeister
countrymeister asked on
.NET ProgrammingC#SQL
1 Comment1 Solution955 ViewsLast Modified:
I have a List<int> dateList
20130531
20130601
20130603

and a DataTable dt with three columns
(Code string,
BusDate int,
Price double
)
ABC  20130531  5
ABC  20130602  4
ABC  20130603  7
LMN  20130601  3
LMN  20130602  2

I need to get for all the given dates in the List, the corresponding codes and prices.
If the date does not exist in the datatable, get the previous days price. Order by Code and date

The final result set should look like this based on the above example

ABC  20130531  5
ABC  20130601  5
ABC  20130603  7
LMN  20130531  NULL
LMN  20130601  3
LMN  20130603  2

This does not work
 var query = from c in dateList.AsEnumerable()
                        join p in dt.AsEnumerable() on c equals p["BusDate"] into ps
                        from p in ps.DefaultIfEmpty()
                        select new { BusDate = c, Code = p["Code"],  Price = p["Price"] };
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros