It was a good call but I thought this might happen when you try that you recieve the "error CS1977: Cannot use a lambda expression as an argument to a
dynamically dispatched operation without first casting it to a delegate
or expression tree type" error.
I also tried changing the code to but this did not work either
The example you provided returns this error: Expression of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.Object]' cannot be used for parameter of type 'System.String' of method 'System.DateTime Parse(System.String)'
So i figured ok if it thinks it trying to use and object as a string lets convert it to an string sor i tried:
var dateSpecificNodes =@Model.Children.Where("DateTime.Parse(OpeningDate.ToString()) < DateTime.Now");
This returned this error: Expression of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.String]' cannot be used for parameter of type 'System.String' of method 'System.DateTime Parse(System.String)'
Does anyone know if methods have access within the string style lambdas that are implemented here?
If they are then I would be able to do
var dateSpecificNodes =@Model.Children.Where("MyDateJoinFunction(OpeningDate, OpeningTime) < DateTime.Now");
I'm lost. I've tried referencing dynamic else where in the file and it works without the error it just seems to be in this context it errors. Do you have any idea why this would happen?
Add Time string to DateTime object in Where query
Hi
I'm writing a Query that needs to add to fields to one an other so a calculation can be made on 2 seperate fields held in a document.
At the moment I have:
What I need is something like
Where OpeningDate is formatted 02/06/2011 00:00:00 and OpeningTime is formatted 15:00
Please can some one help me out.
Cheers
Jon
Can you try this?
Just make sure that OpeningTime is a string in the format: hh:mm:ss
Cheers, Richard
Hi Richard
It was a good call but I thought this might happen when you try that you recieve the "error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type" error.
I also tried changing the code to but this did not work either
I dont really fancy creating a Class every time I need to merge date and time fields.
Any other ides?
Is the OpeningDate field a string? I think you may have to parse the date.
Something like:
Hi Jason
The example you provided returns this error: Expression of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.Object]' cannot be used for parameter of type 'System.String' of method 'System.DateTime Parse(System.String)'
So i figured ok if it thinks it trying to use and object as a string lets convert it to an string sor i tried:
This returned this error: Expression of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.String]' cannot be used for parameter of type 'System.String' of method 'System.DateTime Parse(System.String)'
Does anyone know if methods have access within the string style lambdas that are implemented here?
If they are then I would be able to do
I'll have a look to see if this is possible.
Cheers for the help
If the query gets more complex, you need to cast it to DynamicNodeList as the .Where string query is somewhat limited.
With the DynamicNodeList you can do regular Linq queries. Not sure what datatype your OpeningDate and OpeningTime are, btw.
Are they both DateTime?
Richard
Checked again and this worked fine using updateDate as DateTime, the OfType(dynamic) drop out of my first reply:
Bummer. I'm still getting my head around this stuff as well. Sounds like Richard's solution is likely the best way to go.
Thanks again Richard but I'm still having problems.
Here is my current code
When ever i try to run this i get the error "error CS0103: The name 'dynamic' does not exist in the current context"
I've added the following name spaces to the code but still no joy
I'm lost. I've tried referencing dynamic else where in the file and it works without the error it just seems to be in this context it errors. Do you have any idea why this would happen?
Cheers
Hi,
I used OfType<dynamic>() instead of OfType(dynamic)
notice the angled brackets, hope this helps...
Richard you're a genius that has sorted it.
Now i need to work out how to get .Skip() and .Take() working with that object.
Thanks so much for the help.
is working on a reply...