More in this section

Forums / General Discussions / object scope

object scope

3 posts, 1 answered
  1. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    23 Nov 2010
    Link to this post
    Hi. 

    I am using SF 4.0 RC

     

    I am trying to create a child page progrmatically and am getting a Telerik.OpenAccess error saying that Object references between two different object scopes are not allowed.

     

    I started out using the sample code to create a page programatically, and that works fine.  To make a child page I edit that code and send a PageNode object to the CreateNewStandardPage() method, like,   CreateNewStandardPage(parentNode).   - the intellisense tells me that an overload for the method expects this, and it compiles.  The code creates the parentNode but chokes on the App.WorkWith block (see below).

     

    the error is  

    Object references between two different object scopes are not allowed.

    The object 'Telerik.Sitefinity.Pages.Model.PageNode' is already managed

    by 'ObjectScopeImpl 0x1436bf3 Telerik.OpenAccess.RT.ObjectScope'

    and was tried to be managed again by

    'ObjectScopeImpl 0x14f90e6 Telerik.OpenAccess.RT.ObjectScope'.

     

    I guess I have to create the parentNode using the same object scope that is used by the App.WorkWith block (?)  If so, how do I do that?

     

    Here is my code


                var mgr = new PageManager();
                // get a template guid ==================================================
                var guidTemplate = mgr.GetTemplates().First().Id;
                // get a PageNode object for the parent page.  This works fine.
                var parentNode = mgr.GetPageNodes().Where(n => n.UrlName == mainPageName).FirstOrDefault();

                App.WorkWith()
                    .Page()
                    .CreateNewStandardPage(parentNode)
                    .Do(pn =>
                    {
                        pn.Title = NewPageName;            // db.table = sf_page_node
                        pn.UrlName = NewPageName;     // db.table = sf_page_node
                        pn.Page.Title = NewPageName;  // db.table = sf_page_data
                    })
               .CheckOut()    // creates a draft version and locks the page
               .SetTemplateTo(guidTemplate)
               .Publish()
               .SaveChanges();
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Nov 2010
    Link to this post
    Hi Phil,

    The problem is that the PageManager gets the parent page node in a different object scope than the Fluent API. In order to work with the same object scope can you try the bellow code:
    var fluent = App.WorkWith().Page();
     var mgr = fluent.PageManager;
     // get a template guid ==================================================
     var guidTemplate = mgr.GetTemplates().First().Id;
     // get a PageNode object for the parent page.  This works fine.
     var parentNode = mgr.GetPageNodes().Where(p => p.UrlName == mainPageName).FirstOrDefault();
     
         fluent.CreateNewStandardPage(parentNode)
         .Do(pn =>
         {
             pn.Title = NewPageName;            // db.table = sf_page_node
             pn.UrlName = NewPageName;     // db.table = sf_page_node
             pn.Page.Title = NewPageName;  // db.table = sf_page_data
         })
    .CheckOut()    // creates a draft version and locks the page
    .SetTemplateTo(guidTemplate)
    .Publish()
    .SaveChanges();


    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    24 Nov 2010
    Link to this post
    That worked beautifully Radoslov.
    It also points out the limits of extension methods/ method chaining.  :-)
    Thanks
3 posts, 1 answered