在Umbraco(v6)中使用"内容"而不是"文档"



我想在更新到v6的解决方案中更新一些来自umbraco v4的过时代码。

我有

entitiesFolder = new umbraco.cms.businesslogic.web.Document(folderId);
entitiesFolder.ReorderChildren(
entitiesFolder.Children.OrderBy(fdoc => fdoc.Text), 
refreshEntireCache);

现在建议使用Umbraco.Core.Models.Content来代替过时的Document。怎样没有找到(像Umbraco一样)任何关于…的文档。。。(

// new version
var toto = new Umbraco.Core.Models.Content(??)
toto.SoirtChildren(???)

你是从剃刀的角度来做这件事的吗?如果是这样,你可以做:

var nodeId = 123;
var myNode = Umbraco.TypedContent(nodeId);
var property = myNode.GetPropertyValue<string>("myStringAlias");

如果你在课堂上做这件事,你必须使用类似的东西

var helper = new UmbracoHelper(UmbracoContext.Current);
var nodeId = 123;
var myNode = helper.TypedContent(nodeId);

(这是未经测试的,但应该有效。)

如果您只是在查询数据并需要对其进行排序,那么使用umbracoHelper是一种很好的方法。它只访问App_Data/umbraco.config中的xml缓存,因此不会访问数据库。

但是,如果您试图以程序方式对内容树中的某些节点进行排序,则需要使用ContentService。当您实际想要以编程方式修改内容节点时,您将需要使用ContentService。您还可以找到类似的介质MediaService

https://our.umbraco.org/Documentation/Reference/Management-v6/Services/ContentService

ApplicationContext.Current.Services.ContentService.Sort(...)

最新更新