Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umbraco: differences between Node, DynamicNode, Content

Then there are many class that represents Umbraco documents:

1) umbraco.cms.businesslogic.Content
2) umbraco.cms.businesslogic.web.Document
3) umbraco.MacroEngines.DynamicNode
4) umbraco.presentation.nodeFactory.Node

Are there any others?

Can you explain what they do, and when to use them?

umbraco.MacroEngines.DynamicNode and umbraco.presentation.nodeFactory.Node seem the same. Perhaps it is better to use Node class because it is faster?

I have a theory:

umbraco.cms.businesslogic.Content and umbraco.cms.businesslogic.web.Document are the representation of cmsContent and cmsDocument DB tables.

umbraco.presentation.nodeFactory.Node and umbraco.MacroEngines.DynamicNode represents the node cached in XML file, to utilize into website. The first is the simply Node, the second is the same Node with added dynamic properties, one for property defined in nodeType. So, I think that Node is faster than DynamicNode

Is there someone that can confirm this?

like image 306
riofly Avatar asked Sep 14 '12 08:09

riofly


1 Answers

Based on personal use:

  1. Content: Never use it directly, rather use the Document|Media|Member api (which inherits from this class).
  2. Document: Use it for Create|Update|Delete operations. It does all of its operation directly to DB, so it should be used for Reading only when you need to values directly from the db.
  3. Node: Use this most: when Reading|Displaying data through usercontrols, code libraries, xslt extensions, etc.
  4. DynamicNode: Razor macros. I have not yet use this one enough to provide more info.

See below for more detail, but no, Node and DynamicNode are not the same (DynamicNode uses Examine and will also fall back to reading from the DB if needed).

umbraco.cms.businesslogic.Content: Content is an intermediate layer between CMSNode and classes which will use generic data. Content is a datastructure that holds generic data defined in its corresponding ContentType. Content can in some sence be compared to a row in a database table, its ContentType holds a definition of the columns and the Content contains the data. Note that Content data in umbraco is not tabular but in a treestructure.

I have never had the need to use this class directly though, as all of its operations are handled by the corresponding subclass, e.g: Document, Media, Member. This class in turns inherits from CMSNode which is the base class for every piece of content data inside umbraco

umbraco.cms.businesslogic.web.Document:Document represents a webpage, published Documents are exposed to the runtime/the public website in a cached xml document.

Use this class when referencing nodes from your "Content Section". It handles CRUD operations. Through this class you also get a reference to the DataType of each property in case you want to render those controls in an aspx page.

umbraco.NodeFactory.Node: It implements the INode interface which exposes read-only methods. All of its information comes from the umbraco cached xml. You will not get access to the controls of each property, rather the values of each formatted depending on the datatype.

You can only use this class for reading operations. It makes it really fast to show data since everything comes from cache (published nodes only).

umbraco.MacroEngines.DynamicNode: It was implemented to work with razor macros. It uses NodeFactory under the hood, which means it also access the cached xml. Although if you use the related DynamicMedia be careful as it uses: 1: ExamineIndex which strips out any html tags, 2: it falls back to its default Media type (db if it isn't in runtime cache) in umbraco_v4.11.5.

Same as the above.

like image 85
radyz Avatar answered Sep 23 '22 05:09

radyz