Compartilhar via


EntityRef<TEntity>.SetEntity Method

Sets the entity to which this EntityRef<TEntity> refers.

Namespace:  Microsoft.SharePoint.Linq
Assembly:  Microsoft.SharePoint.Linq (in Microsoft.SharePoint.Linq.dll)

Syntax

'Declaration
Public Sub SetEntity ( _
    entity As TEntity _
)
'Usage
Dim instance As EntityRef
Dim entity As TEntity

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

Parameters

Remarks

Calling this method with the set accessor of a property that wraps a private EntityRef<TEntity> field enables the property to be written with standard property writing syntax when the property is being assigned an object of type T, rather than type EntityRef<TEntity>, where T is the type of the property (and the type parameter of the private EntityRef<TEntity> field).

The SetEntity(TEntity) calls the OnChanging handler before it writes the value to the field and then it calls the OnChanging handler after writing the value.

Examples

The following code shows GetEntity() in use:

[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

See Also

Reference

EntityRef<TEntity> Class

EntityRef<TEntity> Members

Microsoft.SharePoint.Linq Namespace