---
title: Page relationships
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Relationship names (types)

### Creating a relationship name

```csharp

// Creates a new relationship name object
RelationshipNameInfo newName = new RelationshipNameInfo();

// Sets the relationship name properties
newName.RelationshipDisplayName = "New relationship";
newName.RelationshipName = "NewRelationship";

// Saves the relationship name to the database
RelationshipNameInfo.Provider.Set(newName);

```

[> Back to list of examples](#toc)

### Updating a relationship name

```csharp

// Gets the relationship name
RelationshipNameInfo updateName = RelationshipNameInfo.Provider.Get("NewRelationship");

if (updateName != null)
{
    // Updates the relationship name properties
    updateName.RelationshipDisplayName = updateName.RelationshipDisplayName.ToLower();

    // Saves the updated relationship name to the database
    RelationshipNameInfo.Provider.Set(updateName);
}

```

[> Back to list of examples](#toc)

### Updating multiple relationship names

```csharp

// Gets all relationship names whose code name starts with 'New'
var relationshipNames = RelationshipNameInfo.Provider.Get().WhereStartsWith("RelationshipName", "New");

// Loops through individual relationship names
foreach (RelationshipNameInfo name in relationshipNames)
{
    // Updates the relationship name properties
    name.RelationshipDisplayName = name.RelationshipDisplayName.ToUpper();

    // Saves the updated relationship name to the database
    RelationshipNameInfo.Provider.Set(name);
}

```

[> Back to list of examples](#toc)

### Assigning a relationship name to a site

```csharp

// Gets the relationship name
RelationshipNameInfo relationshipName = RelationshipNameInfo.Provider.Get("NewRelationship");

if (relationshipName != null)
{
    // Allows the relationship name to be used on the current site
    RelationshipNameSiteInfo.Provider.Add(relationshipName.RelationshipNameId, SiteContext.CurrentSiteID);
}

```

[> Back to list of examples](#toc)

### Removing a relationship name from a site

```csharp

// Gets the relationship name
RelationshipNameInfo relationshipName = RelationshipNameInfo.Provider.Get("NewRelationship");

if (relationshipName != null)
{
    // Gets the relationship between the relationship name and the current site
    RelationshipNameSiteInfo nameSite =
        RelationshipNameSiteInfo.Provider.Get(relationshipName.RelationshipNameId, SiteContext.CurrentSiteID);

    // Removes the relationship name from the site
    RelationshipNameSiteInfo.Provider.Delete(nameSite);
}

```

[> Back to list of examples](#toc)

### Deleting a relationship name

```csharp

// Gets the relationship name
RelationshipNameInfo deleteName = RelationshipNameInfo.Provider.Get("NewRelationship");

if (deleteName != null)
{
    // Deletes the relationship name
    RelationshipNameInfo.Provider.Delete(deleteName);
}

```

[> Back to list of examples](#toc)

## Page relationships

### Creating and removing a relationship between pages

```csharp

// Gets the relationship name
RelationshipNameInfo relationshipName = RelationshipNameInfo.Provider.Get("NewRelationship");

if (relationshipName != null)
{
    // Gets the pages that will be connected through the relationship
    TreeNode firstPage = new DocumentQuery<TreeNode>()
                             .Path("/FirstPage", PathTypeEnum.Single)
                             .OnSite("MySite")
                             .TopN(1)
                             .FirstOrDefault();

    TreeNode secondPage = new DocumentQuery<TreeNode>()
                              .Path("/SecondPage", PathTypeEnum.Single)
                              .OnSite("MySite")
                              .TopN(1)
                              .FirstOrDefault();

    // Creates the relationship between the pages
    RelationshipInfo.Provider.Add(firstPage.NodeID, secondPage.NodeID, relationshipName.RelationshipNameId);

    // Removes the relationship between the pages
    RelationshipInfo.Provider.Remove(firstPage.NodeID, secondPage.NodeID, relationshipName.RelationshipNameId);
}

```

[> Back to list of examples](#toc)
