Insert objects into a collection with LINQ based on a property of the existing objects in the collection

Posted by DavidS on Stack Overflow See other posts from Stack Overflow or by DavidS
Published on 2011-01-03T08:28:35Z Indexed on 2011/01/03 8:53 UTC
Read the original article Hit count: 209

Filed under:
|

Hi,

I've got a collection of object which contains data as follows:

FromTime                    Duration

2010-12-28                  24.0000

2010-12-29                  24.0000

2010-12-30                  24.0000

2010-12-31                  22.0000

2011-01-02                  1.9167

2011-01-03                  24.0000

2011-01-04                  24.0000

2011-01-05                  24.0000

2011-01-06                  24.0000

2011-01-07                  22.0000

2011-01-09                  1.9167

2011-01-10                  24.0000

In the "FromTime" column, there are data "gaps" i.e. 2011-01-01 and 2011-01-08 are "missing". So what I'd like to do is to loop through a range of dates (in this instance 2010-12-28 to 2011-01-10) and "fill in" the "missing" data with a duration of 0.

As I've just started with LINQ, I feel that it should be "fairly" easy but I can't quite get it right. I'm reading the book "LINQ in Action" but feel that I'm still quite a way off before I can resolve this particular issue. So any help would be much appreciated.

David

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#-4.0