I know that the list of projects is good, as I can remove the where statement and I get the expected list of all the projects. The only hurdle is that last bit where I attempt to see if the mntp (WProjAgency) contains @Model.
e.g. x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.Contains<IPublishedContent>(Model)
Also, the Null Check should be:
x => x.Value<IEnumerable<IPublishedContent>>("WProjAgency") is not null
The full statement that works is:
x => x.Value<IEnumerable<IPublishedContent>>("WProjAgency") is not null && x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.Contains<IPublishedContent>(Model)
LINQ, MNTP and the current node
In Umbraco 10, I'm trying to get a list of projects that have the current node (an agency) picked in an mntp.
My inclination is this:
@foreach (WViewProject project in Umbraco.Content(Guid.Parse("258f6eb4-a07c-4cb1-9b9a-20b021ea296f"))!.Children()!.Where(x => x.Value<string>("WProjAgency") != "" && x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.ContainsAny<IPublishedContent>(Model)).OrderBy(x => x.Value<string>("WWpPropTitleShort")))
I know that the list of projects is good, as I can remove the
where
statement and I get the expected list of all the projects. The only hurdle is that last bit where I attempt to see if the mntp (WProjAgency
) contains@Model
.For clarity:
&& x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.ContainsAny<IPublishedContent>(Model)
I think I'm fairly close, just missing a small element.
That said, if there is a more eloquent way to do this, please let me know.
Solved... Two errors in the code above.
ContainsAny()
should beContains()
e.g.
x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.Contains<IPublishedContent>(Model)
Also, the Null Check should be:
x => x.Value<IEnumerable<IPublishedContent>>("WProjAgency") is not null
The full statement that works is:
x => x.Value<IEnumerable<IPublishedContent>>("WProjAgency") is not null && x.Value<IEnumerable<IPublishedContent>>("WProjAgency")!.Contains<IPublishedContent>(Model)
is working on a reply...