C# 嵌套列表Linq返回1个确定列表

C# 嵌套列表Linq返回1个确定列表,c#,linq,asp.net-mvc-4,C#,Linq,Asp.net Mvc 4,我们有一个包含嵌套列表的列表 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;} } 公开课问题 { 公共字符串问题{get;set

我们有一个包含嵌套列表的列表

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;}
}
公开课问题
{
公共字符串问题{get;set;}
公共列表标记{get;set;}
}
公共类标签
{
公共字符串标记名{get;set;}
公共字符串标记说明{get;set;}
}
然后我们有一个过程,其中GetQuestions()返回问题列表

public List<Tag> QuestionTags(int Type)
{
DAQuestions da = new DAQuestions();
var t = (from d in da.GetQuestions(Type)
               )
                select d.Tags).ToList();
}
公共列表问题标签(int类型)
{
DAQuestions da=新的DAQuestions();
var t=(从da.GetQuestions(Type)中的d开始)
)
选择d.Tags).ToList();
}
我们试图实现的是返回一个确定的标签列表(没有重复)

我们现在返回的是一个

List<List<Tag>>
列表

您需要使用以下内容:

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

Distinct
依赖于查询提供程序筛选出相同的标记,因此它取决于您使用的OR/M。

使用
SelectMany
平展您的
列表
,并实现
IEqualityComparer
从该列表中获取不同的值。见: