Fill a collection from a database with all values filled I have some data in a database, organized like (time, category, value), and basically, I want to show it in a histogram. But the library I use to draw historgrams only works properly if every value is filled. 

For instance, this does not work:

bin category value
1   A        5
2   B        3


But this is ok:

bin category value
1   A        5
2   A        0
1   B        0
2   B        3


So I have to insert zeros for every time/category combination that are not in the database. I came up with the following code:

List&lt;Info&gt; allCategories = GetAllCategories(cnn); //select distinct ...
var data = new List&lt;Info&gt;();
using (var cmd = cnn.CreateCommand())
{
    cmd.CommandText = sqlSelect;
    while (blah blah)
    {
        [setting command parameters]

        //prepare a copy of reference values
        var valuesToAdd = new List&lt;Info&gt;(allCategories.Count);
        foreach (var x in allCategories)
            valuesToAdd.Add(x.Clone());
        int bin = [get bin]
        foreach (var info in valuesToAdd)
            info.Bin = bin;

        using (var reader = cmd.ExecuteReader())
        while (reader.Read())
        {
            int category = reader.GetInt32(1);
            Info info = valuesToAdd.Find(i =&gt; i.category == category); //get the the object to modify
            info.value = reader.GetInt64(2);
        }
        data.AddRange(valuesToAdd);
    }
}
return data;


So, basically I make a copy of the list of possible combination for each bin of the graph, and then I update the values found in the database.

I'm not really fond of this solution, partly because it involves a .Clone, and I'm looking for a more elegant solution...
Have you considered linq? Something like:

        var j = from i in new[] {1, 2}
                from s in new[] {"a", "b"}
                select new {i, s};


or in method syntax:

        var j = new[] {1, 2}.SelectMany(i =&gt; new[] {"a", "b"}, (i, s) =&gt; new {i, s});