I come up with this:
public partial class Forum
{
public List<Forum> GetHierachy(Forum foru)
{
foreach (var forum in foru.SubForums.ToList())
{
yield return GetHierachy(forum);
}
}
}
For this:
public partial class Forum
{
public int Id { get; set; }
public int SubForumId { get; set; }
public virtual ICollection<Forum> SubForums { get; set; }
public virtual Forum ParentForum { get; set; }
}
And I get that:
The body of 'Jami.Data.Forum.GetHierachy(Jami.Data.Forum)' cannot be an iterator block because 'System.Collections.Generic.List<Jami.Data.Forum>' is not an iterator interface type:
Then I found out this: Some help understanding "yield"
So I changed my method to:
public IEnumerable<Forum> GetHierachy(Forum foru)
{
foreach (var forum in foru.SubForums.ToList())
{
yield return GetHierachy(forum);
}
}
And Now I'm getting missing cast exception.
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Jami.Data.Forum>' to 'Jami.Data.Forum'. An explicit conversion exists (are you missing a cast?)
A this point I have no slighest idea why this exception occurs. I might be wrong, but for me it looks like returning collection not single item.