We have moved to GitHub Issues
Created by tuan 13 Jun 2014, 04:52:30 Updated by Ed Parry 24 Nov 2014, 13:04:20
after upgraded to 6.2 version, my code doesn't work anymore.
The problem is with this where condition:
DynamicPublishedContent node = Umbraco.Content(1212); DynamicPublishedContent nodeT = node.Children.Where(x => x.DocumentTypeAlias == "Indice").FirstOrDefault() as DynamicPublishedContent;
Cannot convert lambda expression to type 'string' because it is not a delegate type
Change issue title (was ''Umbraco 6.2 and lambda expression doesn't work anymore #Show-stopper''). See also discussion on Our: http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53022-UmbracoWebModelsDynamicPublishedContentList-does-not-contain-a-definition-for-Any - this is a general issue with DynamicPublishedContentList extension methods.
Note: since 010893a73a08e8f2f8cb3ef45920e0079f56d05f in March 2013, DynamicPublishedContentList implements ''both'' IEnumerable
About the reported issue: nodeT is a DynamicPublishedContent (not a dynamic) and nodeT is a DynamicPublishedContentList (again, not a dynamic). Then, nodeT.Children.Where(...) can either be the builtin DynamicPublishedContentList Where(string) method, or an extension method.
Because DynamicPublishedContentList implements both IEnumerable
About the issue discussed in the "''list does not contain Any()''" thread on Our: same cause, binder fails to infer
Removing the IEnumerable
It's been this way for quite a long time so I'm having trouble remembering exactly why. It probably perhaps due to us also allowing any extension methods on IEnumerable
My first question with the above query is why is dynamic not being used? i.e. why is this using the strongly typed dynamic implementation? There was never an intention to have these classes used directly, these are purely for dynamic purposes and if dynamic is not being used then using IPublishedContent should be used.
The above should be using real strongly typed queries like:
var pNode = Umbraco.TypedContent(1064); var pNodeT = pNode.Children.Where(x => x.DocumentTypeAlias == "Indice").FirstOrDefault();
or using dynamic queries like:
var dNode = Umbraco.Content(1064); var dNodeT = dNode.Children.Where("DocumentTypeAlias=\"Indice\"").FirstOrDefault();
There shouldn't really ever be direct casting to DynamicPublishedContent objects. If there's some strange reason this is necessary, like any other ambiguous extension methods, you'd need to call the extension methods directly, so a work around if you require casing to DynamicPublishedContent is:
DynamicPublishedContent node = Umbraco.Content(1064); DynamicPublishedContent nodeT = Enumerable.Where<IPublishedContent>( node.Children, x => x.DocumentTypeAlias == "Indice").FirstOrDefault() as DynamicPublishedContent;
I'll think more about this for 6.2.2, and whether we remove the IEnumerable
You're right, the source of all confusion is people using DynamicPublishedContent in a non-dynamic way (ie explicitely typing variables as DynamicPublishedContent instead of using the dynamic keyword). It ''may'' be that the correct answer is "don't do it". That's why I put ''confusion'' in the issue title.
Will run more tests to check whether it all works "as expected" if everything is true dynamic.
By my tests, it should be fine to remove the IEnumerable
@zpqrtbnk did you remove it in v7.1.5? I've been trying to recreate a issue with .Count missing in with v7.1.5 source but can't however it's easy to recreate in v7.1.4...
@crumpled_jeavon not at the time you wrote your question.
Just pushed 648cf69d455106e326ef911855f1fd4c24653371 to 7.1.5 which does remove the IEnumerable
Pushed bdc234b18ac71accb1552fe4613f91d516645bc0 to 6.2.2.
Interesting, I have theory on why sometimes .Count() .Any() randomly disappear for dynamics users, it's here http://our.umbraco.org/forum/developers/razor/55558-Adding-ServiceStack-reference-breaks-extension-methods?p=0#comment190962
@zpqrtbnk I'll close this issue as you've fixed it... unless I'm missing something else that is required?
We're still experiencing this issue in 7.1.8. Unable to run code past "CurrentPage.Children.Where("Visisble").Any()", and the same for .Count().
Able to work around the issue by changing "CurrentPage" to "Model.Content".
@edparry Have you installed Analytics for Umbraco? See the thread above, it might break these extension methods: http://our.umbraco.org/forum/developers/razor/55558-Adding-ServiceStack-reference-breaks-extension-methods?p=0#comment190962
@sebastiaan We haven't installed that, no. We have managed to fix the issue by copying the bin and umbraco folders from a working machine across to the machine which had the problem, so it's possible that a dll was out of sync with TFS somewhere along the line.
Assignee: Shannon Deminick
Backwards Compatible: True
Affected versions: 6.2.0, 6.2.1, 7.1.4
Due in version: 7.1.5, 6.2.2