创建节点Sensenet时添加引用

时间:2016-10-26 08:41:17

标签: sensenet

我正在使用,当我在服务器端的代码中创建一个节点时,我有一些令人困惑的事情,我需要向我的节点添加一个引用字段,但我不知道如何做到这一点

我试过像node["user"] = node1

这样的东西

但它不起作用。

2 个答案:

答案 0 :(得分:1)

Sensenet中的所有内容(数据)结构为binary tree,其中Node指的是特定内容对象,如其内容类型定义(CTD)中所指定。当节点引用另一个节点 - 也就是说,它指向树中的另一个位置 - 它可以是两种类型之一。

  1. 它可以指向任何节点,也可以
  2. 它可以被约束为a 特殊类型,如CTD中所述。
  3. 如果您正确分配了参考但得到错误,则可能是您违反了CTD中的类型约束。见下面的例子。

    CTD for reference特定类型的节点(部分)

    <ContentType name="Agent" parentType="GenericContent" handler="Code.ContentHandlers.Agent" xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition">
      <DisplayName>Agent</DisplayName>
      <Icon>Content</Icon>
      <Fields>
    
       <Field name="Category" type="Reference">
          <DisplayName>Agent Category</DisplayName>
          <Description></Description>
          <Configuration>
            <AllowedTypes>
              <Type>AgentCategory</Type>
            </AllowedTypes>
            <VisibleBrowse>Show</VisibleBrowse>
          </Configuration>
        </Field>
    
      </Fields>
    </ContentType>
    

    将节点分配给上面定义的类别参考的示例C#代码。

    var path = "/Root/PathToAgentCategory";
    var agentCat = Node.LoadNode(path) as AgentCategory;
    myAgentNode.Category = agentCat;       // Syntax if you have a ContentHandler
    myAgentNode["Category"] = agentCat;    // Syntax for the GenericContent ContentHandler
    

答案 1 :(得分:0)

你应该阅读它的文件 我发现要添加一个引用字段,你应该使用像这样的东西

node.Addreferences("User", user1);

user1是一个节点,代表您需要引用您的字段的用户

相关问题