给定以下类
public class Entity
{
public IList<Tag> Tags { get; set; }
}
,在我的存储库中,我想获得所有Entity
的所有(不同的)Tag
s,除了
public class Repository()
{
public IList<Tag> GetAllTags()
{
List<Tag> tags = new List<Tag>();
var entities = _session.GetAllEntities();
foreach (var entity in entities)
{
tags.AddRange(entity.Tags);
}
return tags.Distinct().ToList();
}
}
等public class Repository()
{
public IList<Tag> GetAllTags()
{
_session.GetAllEntities().Select(x => x.Tags).....Distinct().ToList()
}
}
public class Repository()
{
public IList<Tag> GetAllTags()
{
var entities = _session.GetAllEntities();
return entities.SelectMany(e => e.Tags).Distinct().ToList();
}
}