Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Espin 368 posts 1335 karma points
    Sep 07, 2014 @ 17:31
    Jason Espin
    0

    Does the content service create content method assign a nodeId

    Hi all,

    Fairly quick question here. When you call the content service such as the code below:

    cs.CreateContent(web_service_item.Title, parentNodeId, documentTypeAlias);
    

    Is the new content node assigned an Umbraco Id at this point or is it when you actually use the save method on the object?

  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Sep 07, 2014 @ 22:11
    Kevin Jump
    101

    Hi

    CreateContent doesn't create the nodeID when you call it, the Identity is set when you save the returned object, the source summarizes it:

    /// Note that using this method will simply return a new IContent without any identity
    /// as it has not yet been persisted. It is intended as a shortcut to creating new content objects
    /// that does not invoke a save operation against the database.
    

    If you want to create a node and have the ID right-away - then cs.CreateContentWithIdentiy will create the content save it and give you the identiy there and then.

    If you want to create something and set so properties then CreateContent is quicker - (as it doesn't save anything to the DB until you tell it to).

    CreateContent: https://github.com/umbraco/Umbraco-CMS/blob/ab092b8814506e82c22abf6eaef11c04625ae3b6/src/Umbraco.Core/Services/ContentService.cs#L181

    CreateContentWithIdentiy: https://github.com/umbraco/Umbraco-CMS/blob/ab092b8814506e82c22abf6eaef11c04625ae3b6/src/Umbraco.Core/Services/ContentService.cs#L281

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies