Obsolete: New way of editing items

Well a new way of editing items fro me :)! Just saw the following part of code in the API Overview(.chm) today:

using (new Sitecore.Data.Items.EditContext(myItem))
{
myItem.Fields[“subject”] = “You did hack Sitecore again today, Alex?”;
}

From now on, I’ll never user Item.Editing again. This Accepts my changes immediatelly and I don’t have to start editing, etc. Are their any more Context-objects available? Well, going to search for them tomorrow. If you know some, please post a comment!
Spent my today today writing more and more security-manipulate code(see post below), will post tomorrow more of the stuff written today.

Update: As you can see the comments of the Sitecore team, the EditContext isn’t preferred anymore. It can be still used for accounts with full rights(Admins) or when you disable the security, but it’s highly recommed to use the Item.Editing object.

4 thoughts on “Obsolete: New way of editing items”

  1. Hi Alex

    I can’t help give you a little info with using “using” statements. Ole and I prefered the “using” method as it seems very clean and intuitive.

    However you can have problems with transactions using “using”s as it works as a try…finally construct.

    Imagine that you update 3 fields:

    using(new EditContext) {
    item.Field[“1”] = “1”;
    item.Field[“2”] = “2”;
    item.Field[“3”] = “3”;
    }

    and the second field throws an exception. This will actually commit the change to field 1, but not field 2 and 3.

    This is why we kept the BeginEdit/EndEdit constructs.

    BTW: Check out SecurityEnabler, SecurityDisabler, SecuritySwitcher and for something really useful: SectionTimer.
    Just thought you should know.

  2. Hi Jakob,

    Thank you for your reply. Good to know the stuff above. Gonna figure out what’s the best way at certain moments.

    I’ve already heard of the Security-options, definitelly interested in the SectionTimer(seen the class in the API, didn’t know what to do with it.

    Thank you for your information.

  3. Hi

    In the old days we acctually recommended use of the EditContext, but we’ve changed best practices for the reasons Jakob explains;

    If an error occours as the changes you’ve applied so far are commited. This endangers the transaction.

Comments are closed.