C# error when using .Where() on CurrentModel.Children
Hi all.
In a line like this in a razor file:
var myVar = CurrentModel.Children.Where(x => x.GetPropertyValue("myProperty") == "myValue");
I get the following errors:
The type arguments for method 'umbraco.MacroEngines.DynamicNodeList.Where<T>(string, params object[])' cannot be inferred from the usage. Try specifying the type arguments explicitly.
and
One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll
I don't get any intellisense for x in the lamda expression.
This only happens in the presentation project, in the website project I get intellisense and no errors are thrown.
It builds every other time, and when it does the code runs as expected.
I am not missing references to the dlls mentioned above I have tried cleaning and rebuilding, I have tried deleting the temporary .NET files (which actually solved the problem for a short while) but now the errors are back and I am out of ideas.
If anyone has any ideas as to why this could be happening please share, it would be greatly appreciated!
Peter, just found it, I never knew that existed! All this time I have done new DynamicNode(Model.Id) and could have just used CurrentModel! Never mind, have moved onto Mvc now :-)
Lewis, any reason you are using Razor Macro rather than Mvc?
Cool, you can always use a "Partial View Macro" within your MasterPages if you would like to make use of the new PublishedContent rather than the legacy DynamicNode :-)
Thanks for the suggestion, it may be something we look into doing. However the original issue still remains a mystery. Why does the code work in one project but not another? Anyone have any ideas?
C# error when using .Where() on CurrentModel.Children
Hi all.
In a line like this in a razor file:
var myVar = CurrentModel.Children.Where(x => x.GetPropertyValue("myProperty") == "myValue");
I get the following errors:
The type arguments for method 'umbraco.MacroEngines.DynamicNodeList.Where<T>(string, params object[])' cannot be inferred from the usage. Try specifying the type arguments explicitly.
and
One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll
I don't get any intellisense for x in the lamda expression.
This only happens in the presentation project, in the website project I get intellisense and no errors are thrown.
It builds every other time, and when it does the code runs as expected.
I am not missing references to the dlls mentioned above I have tried cleaning and rebuilding, I have tried deleting the temporary .NET files (which actually solved the problem for a short while) but now the errors are back and I am out of ideas.
If anyone has any ideas as to why this could be happening please share, it would be greatly appreciated!
Thanks,
Lewis
Should have mentioned, using Umbraco 6.1.5
Hi Lewis,
Could you please post your entire script, especially the definition of CurrentModel?
Thanks,
Jeavon
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
<ul>
@foreach (DynamicNode n in CurrentModel.AncestorsOrSelf().Where(x => x.GetPropertyValue("umbracoNaviHide") != "1"))
{
if(CurrentModel.Id != n.Id)
{
<li><a href="@n.Url">@n.Name</a></li>
continue;
}
<li>n.Name</li>
}
</ul>
}
Because you cant write linq against a dynamic.
Im assuming that this is a Razor scripting file and not a Partial?
Your query should be
var myVar = Model.Children.Where("myProperty" == \"myValue\"");
or use something like uQuery or Node.
Edit on that last one.
var myVar = Model.Children.Where("myProperty == \"myValue\"");
One too many quotes.
The thing is I'm not using Model I am using CurrentModel, which is of type DynamicNode.
Where are you getting CurrentModel from?
By inheriting DynamicNodeContext.
Yep Sorry I missed that you were using CurrentModel and not Model. Jeavon CurrentModel is kinda equivalent to Node.
This works for me.
Peter, just found it, I never knew that existed! All this time I have done
new DynamicNode(Model.Id)
and could have just used CurrentModel! Never mind, have moved onto Mvc now :-)Lewis, any reason you are using Razor Macro rather than Mvc?
No particular reason, but we are too far into the build on this project to make the switch.
Cool, you can always use a "Partial View Macro" within your MasterPages if you would like to make use of the new PublishedContent rather than the legacy DynamicNode :-)
Thanks for the suggestion, it may be something we look into doing. However the original issue still remains a mystery. Why does the code work in one project but not another? Anyone have any ideas?
Peter - the code works for me in other projects, just not this one.
is working on a reply...