Linq / Lambda

The ToModel method returns a IEnumberble of SitemapNodeModel, ToModel accepted a T of IEnumberable IPublishedcontent.
I need to remove ToModel so I wrote the following :
List<SitemapNodeModel> list = new List<SitemapNodeModel>();
foreach (var child in children)
{
				SitemapNodeModel sitemap = new SitemapNodeModel
				{
					Id = child.Id,
					Name = child.Name,
					DocumentTypeAlias = child.DocumentTypeAlias,
					Url = child.Url,
					UrlName = child.UrlName,
					UpdateDate = child.UpdateDate
				};
				
				list.Add(sitemap);
}This works but it can also be done with Linq and Lambda
var children = _umbracoWrapper.Descendants(root)
				.Where(x => _umbracoWrapper.GetPropertyValue<bool>(x, "metaSitemap"))
				.Select(child => new SitemapNodeModel
				{
					Id = child.Id,
					Name = child.Name,
					DocumentTypeAlias = child.DocumentTypeAlias,
					Url = child.Url,
					UrlName = child.UrlName,
					UpdateDate = child.UpdateDate
				}).ToList();
var umbracoNodes = new List<SitemapNodeModel>(children);Last updated
Was this helpful?