> For the complete documentation index, see [llms.txt](https://wiki.owain.codes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.owain.codes/coding/c-sharp/linq-lambda.md).

# Linq / Lambda

<figure><img src="/files/XFsXafs9KpdcvWXB4ssH" alt=""><figcaption></figcaption></figure>

The ToModel method returns a IEnumberble of SitemapNodeModel, ToModel accepted a T of IEnumberable IPublishedcontent.&#x20;

I need to remove ToModel so I wrote the following :&#x20;

```


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&#x20;

```
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);
```
