Linq merging results

Posted by glenneroo on Stack Overflow See other posts from Stack Overflow or by glenneroo
Published on 2011-01-03T07:05:11Z Indexed on 2011/01/03 7:54 UTC
Read the original article Hit count: 252

Filed under:
|
|

I'm working with a list within a list. This is how I'm currently searching:

var tags = from fd in BigList
           from tag in fd.Tags
           where tag.Id == selectedTag.Id ||
                 tag.Id == ID.TIMESTAMP
           select new { fd.Name, tag.Id, tag.Value };

I then iterate over the result-set and remembering when Timestamp pops up for the next entry, needless to say this is sloppy and I'm positive there's a better way using Linq, I just can't seem to find the syntax.

Here's some sample output (Id indicates what type of data is stored inside e.g. a timestamp):

Name | Id | Value
-----|----|----------
0000 | 1  | <timestamp>
0000 | 2  | 1.2
...
9999 | 1  | <timestamp>
9999 | 2  | 6.3

I need all instances where Id = selectedTag.Id. I just want 1 list with Name, Id, Value and Timestamp, but the problem is my above attempt returns 2 entries for every item (1 for timestamp and 1 for the value). Is there a way to do this using Linq? Preferably using query syntax! :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ