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)


Public Sub SetEntity ( _
    entity As TEntity _
Dim instance As EntityRef
Dim entity As TEntity

public void SetEntity(
    TEntity entity



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.


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 {

    // 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
            Return Me._clientRepresentative.GetEntity()
        End Get
        Set(ByVal value As SalesStaff)
        End Set
    End Property

    ' Other members omitted for readability.
End Class

See Also


EntityRef<TEntity> Class

EntityRef<TEntity> Members

Microsoft.SharePoint.Linq Namespace