I have a multi-hierarchical class structure. That is a 'topic' can have many children and a 'topic' can belong to more than one parent. Here is my class structure:
public abstract class Hierarchy <T>{
public virtual ICollection<T> Parents { get; set; }
public virtual ICollection<T> Children{ get; set; }
}
public class Topic: Hierarchy <T>
{
public long ID {get;set;}
public string Title{get;set;}
}
Now for each topic along with Id, Title, I want to select all child Ids (should include nested children as well).
This is my query:
var result = from x in db.topics
select new TopicsDO{
Id = x.Id,
Title = x.Title,
ChildIds = x.Children.SelectMany(x=>x.Id) //This does not give nested child Ids, it just returns the immediate child Ids.
}
Thanks for help.