I would like to be able to get a Linq to Umbraco entity (the strongly typed models of the actual documents) that represents the requested page. Similar to umbraco.NodeFactory.Node.GetCurrent() but with the strongly typed entity returned instead.
Is there a way to instantiate an entity from a node? So far the only way I see to do it is to do a lookup on the ID. MyDataContext.MyObjects.Single(i => i.Id == currentNodeId)
Also it would be nice to be able to make it generic such that I could just specify a type and convert the current node to it. Something like
public static T Active<T>() { return DocTypeBase.GetFromNode<T>(umbraco.NodeFactory.Node.GetCurrent()); }
I think I mostly found my answer, but I wonder if there isnt a more effecient way. This is an additional method on the data context added via a seperate partial class
public T Active() where T: DocTypeBase, new() { return DataProvider.Load(umbraco.NodeFactory.Node.getCurrentNodeId()); }
Can you anyone think of a more effecient (in terms of run time) to do this?
EDIT:
Having played a bit this, it should be noted that the DataProvider.Load method will populate the object with only the properties from the object. Any relationships it might have with sub types will not be populated
Convert INode to Linq to Umbraco Entity
I would like to be able to get a Linq to Umbraco entity (the strongly typed models of the actual documents) that represents the requested page. Similar to umbraco.NodeFactory.Node.GetCurrent() but with the strongly typed entity returned instead.
Also it would be nice to be able to make it generic such that I could just specify a type and convert the current node to it. Something like
Does that make any sense?
I think I mostly found my answer, but I wonder if there isnt a more effecient way. This is an additional method on the data context added via a seperate partial class
Can you anyone think of a more effecient (in terms of run time) to do this?
EDIT:
Having played a bit this, it should be noted that the DataProvider.Load method will populate the object with only the properties from the object. Any relationships it might have with sub types will not be populated
is working on a reply...