-1

We have a list that contains a nested list ie.

public class Question
{
  public string Question { get; set;}
  public List<Tag> Tags { get; set; }
}

public class Tag
{
  public string TagName { get; set;}
  public string TagDescription { get; set;}
}

We then have a procedure where GetQuestions() returns a list of questions

public List<Tag> QuestionTags(int Type)
{
DAQuestions da = new DAQuestions();
var t = (from d in da.GetQuestions(Type)
               )
                select d.Tags).ToList();
}

What we are trying to achieve it to return back 1 definitive list of tags (no duplicates).

What we have returning at the moment is a

List<List<Tag>>
Simon
  • 1,412
  • 4
  • 20
  • 48
  • 1
    Use `SelectMany` to Flatten your `List>` and implement `IEqualityComparer` to get distinct values from that list. See: http://msdn.microsoft.com/en-us/library/vstudio/bb338049(v=vs.100).aspx – Habib Oct 06 '14 at 15:27

1 Answers1

1

You need to use something like this:

da.GetQuestions(Type).SelectMany(q => q.Tags).Distinct().ToList();

Distinct relies on query provider to filter out identical tags, so it depends on OR/M that you use.

takemyoxygen
  • 4,294
  • 22
  • 19