so my domain model has a property named Children
which returns all menus with the ID of the current object. I want to create a view model and in controller map the values between them. So Children
property is IEnumerable<MenuModel>
and menu.Children
is of type IEnumerable<MenuCache>
. What would be the easiest way to do it? Do I need to spin through all children and add them manually to current model and just repeat that for all levels?
Model:
public class MenuModel
{
public int ID { get; set; }
public string URL { get; set; }
public int ParentID { get; set; }
public IEnumerable<MenuModel> Children { get; set; }
}
Controller:
using (var context = ww.WebObjs.WebDataContext.Get())
{
var menu = context.MenuCaches.Where(x=> x.ID == 0).FirstOrDefault();
model = new MenuModel()
{
ID = menu.ID,
URL = menu.Text,
ParentID = menu.ParentID,
Children = menu.Children // how do I get those children?
};
}