使用 API 创建动态内容记录导致 system_parent_id = null
Create Dynamic Content record with API results in system_parent_id = null
我很想知道这个问题的答案。我正在使用 Sitefinity API 为父项创建子项。 (这些是动态模块中的动态内容类型)
在设置属性结束时,我执行以下操作:
historicDataEntry.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
dynamicModuleManager.Lifecycle.Publish(historicDataEntry);
historicDataEntry.SetParent(GetFundIDToUse(), etfType.FullName);
dynamicModuleManager.SaveChanges();
结果是 sf_dynamic_content table 中的两条记录,这是正确的,但由于某种原因,第二条记录的 system_parent_id 为 null,即使它获得了值 visible = 1 和状态 = 2。
好像我在这个过程中遗漏了一些东西,因为创建实时记录时它没有复制 parent_id,即使主记录正确引用了父 ID。
如果我进入管理界面,打开我创建的记录并单击发布,然后它会正确复制父 ID,但 API 方法不会这样做。为什么?
您绝对应该在调用发布之前和设置工作流状态之前设置父级。
这是一个示例代码:
var parentMasterId = Id_of_the_parent_item;
// type is the full name of the dynamic module
string resolvedType = TypeResolutionService.ResolveType(type);
// create the child item
var itemToCreate = manager.CreateDataItem(resolvedType);
// set some other properties of the child, like Title, etc.
// set the parent of the child
itemToCreate.SetParent(parentMasterId, "full_name_of_the_parent_type");
itemToCreate.SetWorkflowStatus(manager.Provider.ApplicationName, "Published");
manager.Lifecycle.Publish(itemToCreate);
manager.SaveChanges();
我很想知道这个问题的答案。我正在使用 Sitefinity API 为父项创建子项。 (这些是动态模块中的动态内容类型)
在设置属性结束时,我执行以下操作:
historicDataEntry.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
dynamicModuleManager.Lifecycle.Publish(historicDataEntry);
historicDataEntry.SetParent(GetFundIDToUse(), etfType.FullName);
dynamicModuleManager.SaveChanges();
结果是 sf_dynamic_content table 中的两条记录,这是正确的,但由于某种原因,第二条记录的 system_parent_id 为 null,即使它获得了值 visible = 1 和状态 = 2。
好像我在这个过程中遗漏了一些东西,因为创建实时记录时它没有复制 parent_id,即使主记录正确引用了父 ID。
如果我进入管理界面,打开我创建的记录并单击发布,然后它会正确复制父 ID,但 API 方法不会这样做。为什么?
您绝对应该在调用发布之前和设置工作流状态之前设置父级。
这是一个示例代码:
var parentMasterId = Id_of_the_parent_item;
// type is the full name of the dynamic module
string resolvedType = TypeResolutionService.ResolveType(type);
// create the child item
var itemToCreate = manager.CreateDataItem(resolvedType);
// set some other properties of the child, like Title, etc.
// set the parent of the child
itemToCreate.SetParent(parentMasterId, "full_name_of_the_parent_type");
itemToCreate.SetWorkflowStatus(manager.Provider.ApplicationName, "Published");
manager.Lifecycle.Publish(itemToCreate);
manager.SaveChanges();