Hi guys I´m trying to execute the following query.
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent query= umbHelper.TypedContent(34924).Children.Where(x=>x.system=="north");
var query= umbHelper.TypedContent(34924).Children.Where(x => x.system=="north");
Gives me the same error.
Where is this code running from (e.g., action method in controller, CSHTML file)?
I´m running my using action method in controller
What happens if you add using System.Linq at the top of your file?
It seems strange to me that you are able to type x.system=="north", as I don't believe "system" is a property on IPublishedContent. It's almost like that's using the dynamic syntax or something. What happens when you try this:
var query = umbHelper.TypedContent(34924).Children.ToList().Where(x => true == true);
You might also try:
var query = umbHelper.TypedContent(34924).Children().ToList().Where(x => true == true);
You can also run the Where extension method directly as a static function call, but I'm not sure of the exact code (I don't have an IDE open at the moment). I imagine it would look something like this:
var query = System.Linq.CollectionExtensions.Where(umbHelper.TypedContent(34924).Children.ToList(), x => true == true);
By calling it directly rather than relying on the extension method syntax, you can be sure you are calling the correct function.
var systemValues = umbHelper.TypedContent(34924).Children.Select(x => x.GetPropertyValue<string>("system")).ToList();
My best guess is it will contain an item that says "North" (i.e., the first letter being uppercase). Not really sure what your data looks like though, so I could be wrong. If I am correct by chance, you could probably get it working like this:
var query = umbHelper.TypedContent(34924).Children.Where(x => "North".InvariantEquals(x.GetPropertyValue<string>("system")));
It doesn't have to be uppercase, that's just how I happened to write it. The InvariantEquals function does a case-insensitive comparison (i.e., it ignores uppercase and lowercase).
Error executing query
Hi guys I´m trying to execute the following query.
But it´s returning me the following error:
“Delegate 'System.Func
Does anyone knows how to solve this problem?
Best Regards
What version of Umbraco are you using?
What happens when you "go to definition" on the "Where" function (a screenshot would be useful)?
What happens when you change your code to this:
Where is this code running from (e.g., action method in controller, CSHTML file)?
What happens if you add
using System.Linq
at the top of your file?Hi Nicholas thank you for your reply.
I´m using Umbraco 7.2.1.
Go to definition on the where
When I change my code to:
Gives me the same error.
Where is this code running from (e.g., action method in controller, CSHTML file)? I´m running my using action method in controller What happens if you add using System.Linq at the top of your file?
I already imported System.Linq
Best Regards
It seems strange to me that you are able to type
x.system=="north"
, as I don't believe "system" is a property onIPublishedContent
. It's almost like that's using the dynamic syntax or something. What happens when you try this:You might also try:
You can also run the
Where
extension method directly as a static function call, but I'm not sure of the exact code (I don't have an IDE open at the moment). I imagine it would look something like this:By calling it directly rather than relying on the extension method syntax, you can be sure you are calling the correct function.
Hi Vanilson,
Are you trying to use the models builder to have strongly typed models ?
If not can you try to this line of code ? Because I'm suspecting you are mixing strongly typed and dymanic query syntax. And that doesn't work
To have understanding about the difference between strongly typed and dynamic syntax read this article I wrote for the Umbraco Calendar :
http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/
My advice by the way is to always use the strongly typed IPublishedContent or to use the models builder to generate models from doctypes for you.
Dave
@Nicholas
I made a mistake in the expression, "system" is a property in my document type, above is the query that I´m trying to execute:
@Dave
I execute the query in my controller and it doesn´t return any result.
I have the following structure of contents:
I want to return all the items inside the sub-contents by comparing if the contents are in Content 1 or Content 2 and I´m having problems to do this.
Best Regards
What does this list contain when you run it?
My best guess is it will contain an item that says "North" (i.e., the first letter being uppercase). Not really sure what your data looks like though, so I could be wrong. If I am correct by chance, you could probably get it working like this:
Hi guys, sorry for answering too late. Nicholas it works, but I got one question, why I got to put the North letter in Uppercase?
Best Regards
It doesn't have to be uppercase, that's just how I happened to write it. The
InvariantEquals
function does a case-insensitive comparison (i.e., it ignores uppercase and lowercase).is working on a reply...