After working with another CMS a lot something I was missing when i started an Umbraco project a few days ago was a CurrentPage property. So I created a base class for my masterpages that exposes that property, when leaving the office yesterday running 4.1 RC it was working but when catching up with my RSS last night i noticed that 4.5 is released so I upgraded it this morning and it stopped working... :(
Each masterpage class looks like this:
public partial class Startpage : Foo.Web.UI.MasterPage<Foo.Startpage> { ... }
And the MasterPage<T> base class looks like this:
public class MasterPage<T> : System.Web.UI.MasterPage where T : DocTypeBase, new() { public T CurrentPage { get { int nodeId = Node.GetCurrent().Id;
Solved my own problem by creating an method instead of Load<T>(), GetPage<T>() that seems to be working:
public T GetPage<T>(int nodeId) where T : DocTypeBase, new() { return FooDataContext.Instance.LoadTree<T>().Where(x => x.Id == nodeId).FirstOrDefault(); }
But still it's confusing that Load<T>() doesn't work...
Well I never anticipated this usage for LINQ to Umbraco, and if you're trying to use Load<T> you'll loose a lot in performance (it doesn't work with the cache).
What about caching the data inside the getter of CurrentPage and listen to Document.BeforeSave, Document.BeforeMove etc and clear the cache on those events?
Problems with DataProvider.Load<T>()
After working with another CMS a lot something I was missing when i started an Umbraco project a few days ago was a CurrentPage property. So I created a base class for my masterpages that exposes that property, when leaving the office yesterday running 4.1 RC it was working but when catching up with my RSS last night i noticed that 4.5 is released so I upgraded it this morning and it stopped working... :(
Each masterpage class looks like this:
And the MasterPage<T> base class looks like this:
The FooDataContext.Instance is picked from the video by Aaron Powell here: http://vimeo.com/9790069 and looks like this:
When I access any property on CurrentPage it throws this exception (Stack trace):
Am I missing something obvious?
I'm unable to edit my post, the CurrentPage property looks like this:
And the relevant part of the stack trace for accessing a property on CurrentPage is this:
Solved my own problem by creating an method instead of Load<T>(), GetPage<T>() that seems to be working:
But still it's confusing that Load<T>() doesn't work...
Well I never anticipated this usage for LINQ to Umbraco, and if you're trying to use Load<T> you'll loose a lot in performance (it doesn't work with the cache).
So whats the recommended way to get a strongly typed "CurrentPage" ?
There isn't. LINQ to Umbraco doesn't have a concept of 'current page', it doesn't understand hierarchy. That's now how it's designed.
What about caching the data inside the getter of CurrentPage and listen to Document.BeforeSave, Document.BeforeMove etc and clear the cache on those events?
is working on a reply...