object scope

Posted by Community Admin on 03-Aug-2018 23:22

object scope

All Replies

Posted by Community Admin on 23-Nov-2010 00:00

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();

Posted by Community Admin on 24-Nov-2010 00:00

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

Posted by Community Admin on 24-Nov-2010 00:00

That worked beautifully Radoslov.
It also points out the limits of extension methods/ method chaining.  :-)
Thanks

This thread is closed