Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Umbraco关系类型_Umbraco_Umbraco6 - Fatal编程技术网

Umbraco关系类型

Umbraco关系类型,umbraco,umbraco6,Umbraco,Umbraco6,在Umbraco 6.1.6的开发者部分,有一个关系类型节点 谁能解释一下什么是关系类型,以及它们是否有实际应用。我看过一些文档,但仍然不确定为什么我可能需要使用它们 它们在v6和v7中仍然相关吗?我最近开始记录,这将为您提供一些关于如何使用它的见解。我偶尔使用它来维护内容树中节点之间的关系 如果您在Umbraco中复制了一个节点,您可以选择将新节点与原始节点关联,该节点使用一种称为“复制时关联文档”的关系类型。例如,有了关系,您就可以挂接到诸如Save事件之类的事件中,并且每当更新父节点时,您

在Umbraco 6.1.6的开发者部分,有一个关系类型节点

谁能解释一下什么是关系类型,以及它们是否有实际应用。我看过一些文档,但仍然不确定为什么我可能需要使用它们


它们在v6和v7中仍然相关吗?

我最近开始记录,这将为您提供一些关于如何使用它的见解。我偶尔使用它来维护内容树中节点之间的关系

如果您在Umbraco中复制了一个节点,您可以选择将新节点与原始节点关联,该节点使用一种称为“复制时关联文档”的关系类型。例如,有了关系,您就可以挂接到诸如Save事件之类的事件中,并且每当更新父节点时,您也可以更新相关的子节点。这种技术有时用于多语言站点,这些站点希望跨每种语言同步内容

下面是我最近工作的一个项目的一个简短示例,其中可能会创建一个重复事件。我们需要知道该系列中的第一个事件,以及该事件的所有后续事件(子事件)

公共类事件:ApplicationEventHandler
{
受保护的覆盖无效应用程序已启动(UmbracoApplicationBase umbracoApplication、ApplicationContext ApplicationContext)
{
ContentService.Saved+=ContentServiceSaved;
}
私有void ContentServiceSaved(IContentService发送方,SaveEventArgs e)
{
var rs=ApplicationContext.Current.Services.RelationService;
var relationType=rs.GetRelationTypeByAlias(“RepeatedEventToCurence”);
foreach(e.SavedEntities中的IContent内容)
{
var occurrences=rs.GetByParentId(content.Id)。其中(r=>r.RelationType.Alias==“RepeatedEventToCurence”);
bool exists=false;
foreach(var doc in occurrences.Select(o=>sender.GetById(o.ChildId)))
{
//检查此事件是否已经发生,且日期匹配
}
如果(!存在)
{
var newDoc=sender.Copy(content,eventsDoc.Id,true,User.GetCurrent().Id);
//设置需要在新节点上设置的任何属性
...
rs.Relate(内容、新文档、关系类型);
}       
}
}
}
  public class Events : ApplicationEventHandler
  {
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
      ContentService.Saved += ContentServiceSaved;
    }

    private void ContentServiceSaved(IContentService sender, SaveEventArgs<IContent> e)
    {
        var rs = ApplicationContext.Current.Services.RelationService;
        var relationType = rs.GetRelationTypeByAlias("repeatedEventOccurence");

        foreach (IContent content in e.SavedEntities)
        {
            var occurences = rs.GetByParentId(content.Id).Where(r => r.RelationType.Alias == "repeatedEventOccurence");
            bool exists = false;

            foreach (var doc in occurences.Select(o => sender.GetById(o.ChildId)))
            {
                // Check if there is already an occurence of this event with a matching date
            }

            if (!exists)
            {
                var newDoc = sender.Copy(content, eventsDoc.Id, true, User.GetCurrent().Id);

                // Set any properties you need to on the new node
                ...

                rs.Relate(content, newDoc, relationType);
            }       
        }
    }
}