Partager via


EntityRef<TEntity>.SetEntity - Méthode

Définit l'entité à laquelle fait référence cet EntityRef<TEntity> .

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

Syntaxe

'Déclaration
Public Sub SetEntity ( _
    entity As TEntity _
)
'Utilisation
Dim instance As EntityRef
Dim entity As TEntity

instance.SetEntity(entity)
public void SetEntity(
    TEntity entity
)

Paramètres

Remarques

L'appel de cette méthode avec l'accesseur de set d'une propriété qui encapsule un champ privé EntityRef<TEntity> permet la propriété écriture avec une écriture lorsque la propriété en cours est associée à un objet de type T, plutôt que de type EntityRef<TEntity>, où T est le type de la propriété (et le paramètre de type du champ privé EntityRef<TEntity> ) de syntaxe de propriété standard.

Le SetEntity(TEntity) appelle le Gestionnaire de OnChanging avant qu'il écrit la valeur dans ce champ et il appelle ensuite le gestionnaire OnChanging après l'écriture de la valeur.

Exemples

Le code suivant illustre les GetEntity() en cours d'utilisation :

[ContentType(Name="Item", Id="0x01", List="Clients")]
public partial class ClientsItem : Item 
}
    private EntityRef<SalesStaff> _clientRepresentative;

    [Association(Name="ClientRepresentative", Storage="_city", MultivalueType=AssociationType.Single, List="Sales Staff")]
    public SalesStaff ClientRepresentative {
        get {
            return this._clientRepresentative.GetEntity();
        }
        set {
            this._clientRepresentative.SetEntity(value);
        }
    }

    // Other members omitted for readability.
}
<ContentType(Name:="Item", Id:="0x01", List:="Clients")>
Partial Public Class ClientsItem
    Inherits Item
    Private _clientRepresentative As EntityRef(Of SalesStaff)

    <Association(Name:="ClientRepresentative", Storage:="_city", MultivalueType:=AssociationType.Single, List:="Sales Staff")>
    Public Property ClientRepresentative() As SalesStaff
        Get
            Return Me._clientRepresentative.GetEntity()
        End Get
        Set(ByVal value As SalesStaff)
            Me._clientRepresentative.SetEntity(value)
        End Set
    End Property

    ' Other members omitted for readability.
End Class

Voir aussi

Référence

EntityRef<TEntity> classe

EntityRef<TEntity> - Membres

Microsoft.SharePoint.Linq - Espace de noms