Umbraco: differences between Node, DynamicNode, Content
Asked Answered
I

3

7

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?

Irmairme answered 14/9, 2012 at 8:27 Comment(0)
M
11

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.

Makepeace answered 14/3, 2013 at 21:25 Comment(1)
The statement DynamicNode using Examine - but then also reading from DB ("if it isn't in runtime cache") seems to conflict. What do you mean by the runtime cache here? I generally assume that HTTPRuntime that Umbraco uses for in-memory cache: but Examine is not that cache.Assemble
F
3

I just know the difference between Document and Node. The Node class uses the data stored in the umbraco cache, the Document class will get data directly from the database. Node is faster than Document. Node only returns the content that is saved and published.

95% of time you should use Node.

Fining answered 14/9, 2012 at 8:45 Comment(0)
P
0

Content allows you to retrieve/edit any content (page/media/..) from DB (including non-published content), Document allows you to retrieve/edit only page content from DB (including non-published content), Node is used for fast read-only access to (published only) page content from the XML cache and Dynamic Node is comparable to Node but implemented in later versions of Umbraco for macros using Razor

Pragmatist answered 13/2, 2013 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.