SPFieldLookup.PrimaryFieldId - Propriété

Obtient ou définit une représentation sous forme de chaîne du GUID qui identifie le champ de recherche principal si le champ est un champ de recherche dépendant.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Property PrimaryFieldId As String
    Get
    Set
'Utilisation
Dim instance As SPFieldLookup
Dim value As String

value = instance.PrimaryFieldId

instance.PrimaryFieldId = value
public string PrimaryFieldId { get; set; }

Valeur de propriété

Type : System.String
Si le champ est un champ secondaire dans une recherche de plusieurs colonne, cette propriété retourne la représentation sous forme de chaîne du GUID qui identifie le champ de recherche principal ; dans le cas contraire, elle renvoie une chaîne vide.

Exceptions

Exception Condition
SPException

Vous ne pouvez pas modifier la valeur de cette propriété après que qu'il a été défini.

NotSupportedException

Le champ appartient à une liste externe.

Remarques

Lorsque vous créez une recherche multiples de la colonne, le champ primaire est l'objet SPFieldLookup qui établit la relation avec la liste source. Un ou plusieurs champs secondaires dépendent du champ primaire de la relation à la liste source.

Si la propriété IsDependentLookup de l'objet SPFieldLookup en cours retourne true, puis l'objet actuel est un champ secondaire et sa propriété PrimaryFieldId retourne la représentation sous forme de chaîne du GUID qui identifiant le champ de recherche principal dont il dépend.

Exemples

L'exemple suivant est une application console qui examine la collection de champs associés à une liste, recherche d'objets SPFieldLookup . Lorsqu'il en trouve un, le code dans l'application détermine si l'objet représente une colonne principale ou secondaire. Si l'objet représente une colonne secondaire, le code utilise la valeur retournée par la propriété PrimaryFieldId pour obtenir le nom complet de la colonne primaire.

using System;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite("https://localhost"))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    SPList list = site.Lists["Complete Orders"];

                    foreach (SPField item in list.Fields)
                    {
                        if (item is SPFieldLookup)
                        {
                            SPFieldLookup field = (SPFieldLookup)item;

                            if (!String.IsNullOrEmpty(field.LookupList) && !String.IsNullOrEmpty(field.LookupField))
                            {
                                // Is this the primary or secondary field for a list relationship? 
                                string strRelationship = field.IsRelationship ? "Primary":"Secondary"; 

                                // Print the display name of the field.
                                Console.WriteLine("\nField: {0} ({1} Field)", field.Title, strRelationship);

                                // Is this a secondary field in a list relationship?
                                if (field.IsDependentLookup)
                                {
                                    SPField primaryField = list.Fields[new Guid(field.PrimaryFieldId)];
                                    Console.WriteLine("Primary Field: {0}", primaryField.Title);
                                }
                            }
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using siteCollection As New SPSite("https://localhost")
            Using site As SPWeb = siteCollection.OpenWeb()
                Dim list As SPList = site.Lists("Pending Orders")

                For Each item As SPField In list.Fields
                    If TypeOf item Is SPFieldLookup Then
                        Dim field As SPFieldLookup = DirectCast(item, SPFieldLookup)

                        If Not String.IsNullOrEmpty(field.LookupList) AndAlso Not String.IsNullOrEmpty(field.LookupField) Then
                            ' Is this the primary or secondary field for a list relationship?
                            Dim strRelationship As String = If(field.IsRelationship, "Primary", "Secondary")

                            ' Print the display name of the field.
                            Console.WriteLine(vbLf & "Field: {0} ({1} Field)", field.Title, strRelationship)

                            ' Is this a secondary field in a list relationship?
                            If field.IsDependentLookup Then
                                Dim primaryField As SPField = list.Fields(New Guid(field.PrimaryFieldId))
                                Console.WriteLine("Primary Field: {0}", primaryField.Title)
                            End If
                        End If
                    End If
                Next
            End Using
        End Using
        Console.Write(vbLf & "Press ENTER to continue...")
        Console.ReadLine()
    End Sub
End Module

Voir aussi

Référence

SPFieldLookup classe

SPFieldLookup - Membres

Microsoft.SharePoint - Espace de noms

IsDependentLookup

AddDependentLookup(String, Guid)