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

Last updated

Was this helpful?