I have an entity that is actually tree object structure (defining only relevant properties within my entity):
public class TreeItem
{
public int Id { get; set; }
public TreeItem Parent { get; set; }
public List<TreeItem> Children { get; set; }
...
}
Parent and Children properties are correctly defined as navigational properties. So when I call something like:
var items = (from ti in context.TreeItem()
select ti).ToList<TreeItem>();
I actually get my items in a tree structure, because EF works its magic behind the curtain and populates my Parents and Children on these items.
What I would like to do now is to convert these objects into my ViewModel objects that are very much POCO. No functionality, just data.
I could convert these by having a recursive method that would create and populate new objects, but is there a simpler (in terms of LoC - lines of code) way to do this kind of conversion?