I'm tryin to do a .Where() Filter on my nodes with multiple Ids.
I have been trying to use .ContainAny() with no luck so far.
Here's what i got:
var values = new Dictionary<string,object>(); var keywords = new List<string>(); keywords.Add("1222"); keywords.Add("1193"); values.Add("keywords",keywords); // Doesn't Work //Children = Children.Where("Id.Contains(1222)");
// Works //Children = Children.Where("Convert.ToString(Id).Contains(\"1222\")");
There are a few problems with what you are trying to do:
Firstly, in general LINQ queries then Contains() operates on an IEnumerable collection not on a single Int. So given that the Id of a node is of type Int, how can an Int contain anything? Saying Id.Contains(1234) makes no sense. How can a single integer number contain anything?
Your second problem is that Where in Umbraco razor doesn't, as far as I know, implement Contains.
However, if you have a list of node Ids and want to find nodes in a list of child nodes then you could do something like this:
List idsList = new List() { 1064, 1065 };
dynamic foundNodes = CurrentModel.Descendants(x => idsList.Contains(x.Id));
foreach (var n in foundNodes)
{
@n.Id
}
Razer .Where(Id One Of Multiple Ids)
I'm tryin to do a .Where() Filter on my nodes with multiple Ids.
I have been trying to use .ContainAny() with no luck so far.
Here's what i got:
Appreciate your help.
There are a few problems with what you are trying to do:
Firstly, in general LINQ queries then Contains() operates on an IEnumerable collection not on a single Int. So given that the Id of a node is of type Int, how can an Int contain anything? Saying Id.Contains(1234) makes no sense. How can a single integer number contain anything?
Your second problem is that Where in Umbraco razor doesn't, as far as I know, implement Contains.
However, if you have a list of node Ids and want to find nodes in a list of child nodes then you could do something like this:
Thanks Diplo.
Love the cheatsheet, been missing it for awhile :)
You got me thinking and i'll take a different approach, something like:
is working on a reply...