object scope
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
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();
That worked beautifully Radoslov.
It also points out the limits of extension methods/ method chaining. :-)
Thanks