I was trying to do something a little more advanced, I'm looking for all articles that have (in a multinode picker) one of the following Id's in them: 5182,5183 or 5184.
Just wanted to present a simplified version here, so I tried above code but I get the same error I've been getting before:
No applicable method 'Contains' exists in type 'Func`2'
Okay, this is probably a use-case for a more advanced selection method.
If you can somehow iterate over the IDs you want, you can call Model.NodeById(...) and pass that in. That will give you each node in turn. If they're media items, use Model.MediaById(...)
If the use-case is selecting multiple nodes by ID number, then I'd probably implement this as overloads on those two methods. If it's searching/filtering complex like the ipsum sample below, I'm not sure what the best signature would be - open to suggestions.
What will be happening with the Contains in the where is at the time it evaluates that, it doesn't know that it's a Dynamic - it's a path I haven't upgraded for DynamicNode yet
I'd be interested in some suggestions about how the code should read in the .cshtml file
Nah, I am really trying to compare two arrays (which I know is pretty hard to do in Linq anyway), here's something I threw together in uQuery real quickly:
var picker = Model.KeywordsPicker.ToString().Split(',');
var foundNodes = new List();
foreach (var p in picker)
{
var currentP = p;
var nodes = uQuery.GetRootNode().GetDescendantNodes().Where(x => x.GetPropertyAsString("keywordsPicker").Split(',').Any(k => k == currentP));
foreach (var n in nodes.Where(n => foundNodes.Contains(n) == false))
{
foundNodes.Add(n);
}
}
With regards to more of a "normal" Contains method, I think the one in my opening post look quite right. But while you're building that, you might run into problems with empty values though, because you can't type them properly..
It's hard to see support for all possible future uses of lambdas put into DynamicNode. Wouldn't it be nice to add some uQuery/uQl IEnumerable<Node>'s node extensions? And functions to convert back and forth from DynamicNodeList <-> IEnumerable<Node> ?
It sounds like the Relations API might be benficial to you here ?
Rather than string chop a CSV, or parse XML fragments for each node, a single DB hit to get all Nodes related to picked NodeIDs should be much quicker.
There's a datatype called MultiPicker Relations in uComponents that can wire up multipickers so that they automatically create the relations.
Thanks Hendy, I really should look into the relations API one day. It's too late for this project, but doing string splits has been giving me enough headaches before! Thanks for the tip!
Should .Contains be working at the moment?
I've tried variations of this, but I keep getting errors, so I'm just wondering if Contains is built in:
I did find an interesting blog post with a sample implementation, might be good to work off of.
No, no support for that yet.
Do you want to return all articles where the bodyText property contains ipsum?
You could try and do it with where, but I haven't tested it.
This is a fairly advanced use-case of where:
Dictionary<string,object> values = new Dictionary<string,object>();
values.Add("keyword", "ipsum");
var searchResults = Model.Children.Where("bodyText.Contains(keyword)", values);
@foreach(var item in searchResults)
{
@item.Name;
}
No promises!
If this doesn't work, we might need a few more IEnumerable implementations for searching/filtering
I was trying to do something a little more advanced, I'm looking for all articles that have (in a multinode picker) one of the following Id's in them: 5182,5183 or 5184.
Just wanted to present a simplified version here, so I tried above code but I get the same error I've been getting before:
No applicable method 'Contains' exists in type 'Func`2'
Okay, this is probably a use-case for a more advanced selection method.
If you can somehow iterate over the IDs you want, you can call Model.NodeById(...) and pass that in. That will give you each node in turn.
If they're media items, use Model.MediaById(...)
If the use-case is selecting multiple nodes by ID number, then I'd probably implement this as overloads on those two methods.
If it's searching/filtering complex like the ipsum sample below, I'm not sure what the best signature would be - open to suggestions.
What will be happening with the Contains in the where is at the time it evaluates that, it doesn't know that it's a Dynamic - it's a path I haven't upgraded for DynamicNode yet
I'd be interested in some suggestions about how the code should read in the .cshtml file
Nah, I am really trying to compare two arrays (which I know is pretty hard to do in Linq anyway), here's something I threw together in uQuery real quickly:
With regards to more of a "normal" Contains method, I think the one in my opening post look quite right. But while you're building that, you might run into problems with empty values though, because you can't type them properly..
It's hard to see support for all possible future uses of lambdas put into DynamicNode. Wouldn't it be nice to add some uQuery/uQl IEnumerable<Node>'s node extensions? And functions to convert back and forth from DynamicNodeList <-> IEnumerable<Node> ?
Hi Sebastiaan,
It sounds like the Relations API might be benficial to you here ?
Rather than string chop a CSV, or parse XML fragments for each node, a single DB hit to get all Nodes related to picked NodeIDs should be much quicker.
There's a datatype called MultiPicker Relations in uComponents that can wire up multipickers so that they automatically create the relations.
HTH,
Hendy
Thanks Hendy, I really should look into the relations API one day. It's too late for this project, but doing string splits has been giving me enough headaches before! Thanks for the tip!
i've just tried the following code like Garath suggested
but i get the following error
never mind, its ok :)
seems like i forgot checking the filter for null
Have got some unit tests working for this kind of thing in 4.10 and have created a task for it:
http://issues.umbraco.org/issue/U4-995
Pretty much all methods and extension methods should work dynamically now.
is working on a reply...