As a relative newbie to Umbraco and especially Lambda expressions, I've been struggling with something that should be so simple (which I understand to be the point of Lambda expressions!), but it's taken me on a road to nowhere, and after googling and trying many things, I've more or less given in.
All I want to do is return a list of nodes that match a date criteria. Basically I have a document type with a date picker control on it, and I want to return all nodes that have a date > today.
I therefore expected the Lambda expression to be something like;
var specificnodes = Model.Content.Where(x => x.eventDate.Value < DateTime.Now);
but I get an exception error of "Cannot convert lambda expression to type 'string' because it is not a delegate type". I assume this is due to me needing to convert something somewhere, but I've tried millions of combinations of .value and so on, but dont really understand what the issue is.
Can anyone make sense of this? I'm using Umbraco 7.2.
In my example you need to change the PropertyAlias in the where so it match your property alias for the date picker on the document type I think it´s the eventDate from your post. In this example above is take the children of the page that you are adding the marco to.
If you have an overview page, and the underneath you have the items that you want in the list then you should place the macro on the template for overview page. I have not tested the code myself, but hope this can help you or at least a step forward.
@Dennis FYI, you can't use the @0 token syntax in a lambda, that's for magic Where strings that are generally only used with the dynamic model (CurrentPage)
Thanks for your help Jeavon and Dennis - very much appreciated!!!
I can't believe that I didnt realise there was a query builder for this, although it still doesnt seem to work that well with dates in Umbraco, in terms of identifying the type differently, and also, it seemed to traverse the tree, rather than using a Lambda expression, which I could have done, but I wanted to understand how to do it more efficiently using a Lambda, as that is what it seemed to be for.
Yes the query builder, but as you say it needs a date picker (there is a issue for that here). Anyway it will generate dynamics (CurrentPage) so not lambda expressions which is what you're after!
Lost in Lambda expressions...
Hello all,
As a relative newbie to Umbraco and especially Lambda expressions, I've been struggling with something that should be so simple (which I understand to be the point of Lambda expressions!), but it's taken me on a road to nowhere, and after googling and trying many things, I've more or less given in.
All I want to do is return a list of nodes that match a date criteria. Basically I have a document type with a date picker control on it, and I want to return all nodes that have a date > today.
I therefore expected the Lambda expression to be something like;
var specificnodes = Model.Content.Where(x => x.eventDate.Value < DateTime.Now);
but I get an exception error of "Cannot convert lambda expression to type 'string' because it is not a delegate type". I assume this is due to me needing to convert something somewhere, but I've tried millions of combinations of .value and so on, but dont really understand what the issue is.
Can anyone make sense of this? I'm using Umbraco 7.2.
Thanks in advance!!
Alwyn
Hi Alwyn,
I think that you can do something like this
In my example you need to change the PropertyAlias in the where so it match your property alias for the date picker on the document type I think it´s the eventDate from your post. In this example above is take the children of the page that you are adding the marco to.
If you have an overview page, and the underneath you have the items that you want in the list then you should place the macro on the template for overview page. I have not tested the code myself, but hope this can help you or at least a step forward.
Hope this helps,
/Dennis
Hi Alwyn,
You are very close, it should be like this:
The part
AncestorOrSelf(1).Children
might be wrong, it depends on where the nodes you want are located in your tree.Jeavon
By the way, did you try the query builder (new button in the template editor) to create this for you?
@Dennis FYI, you can't use the @0 token syntax in a lambda, that's for magic Where strings that are generally only used with the dynamic model (CurrentPage)
@Jeavon Arh okay, then I got a little bit wiser today, thanks for your good explanation. Most of the time I write the dynamic model (CurrentPage) :-)
Thanks for your help Jeavon and Dennis - very much appreciated!!!
I can't believe that I didnt realise there was a query builder for this, although it still doesnt seem to work that well with dates in Umbraco, in terms of identifying the type differently, and also, it seemed to traverse the tree, rather than using a Lambda expression, which I could have done, but I wanted to understand how to do it more efficiently using a Lambda, as that is what it seemed to be for.
Alwyn
Great!
Yes the query builder, but as you say it needs a date picker (there is a issue for that here). Anyway it will generate dynamics (CurrentPage) so not lambda expressions which is what you're after!
is working on a reply...