EntityRef<TEntity> Class

Provides for deferred loading and relationship maintenance for the singleton side of a one-to-many relationship.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Linq.EntityRef<TEntity>

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

Syntax

'Declaration
<DataContractAttribute> _
Public NotInheritable Class EntityRef(Of TEntity As Class) _
    Implements ICloneable
'Usage
Dim instance As EntityRef(Of TEntity)
[DataContractAttribute]
public sealed class EntityRef<TEntity> : ICloneable
where TEntity : class

Type Parameters

  • TEntity
    The type of the entity on the singleton side of the relationship.

Remarks

For example, suppose there a Client list has a SalesRepresentative column that is a lookup field to a Sales Staff list. Each client has just one sales representative, so only single values are allowed in the SalesRepresentative field; but many clients are assigned to the same representative, so this is a many-to-one relation. To implement deferred loading, the ClientRepresentative property wraps a private EntityRef<TEntity> field, where TEntity is SalesStaff, rather than a private SalesStaff type field.

Examples

The following example shows the implementation of the scenario described above:

[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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

EntityRef<TEntity> Members

Microsoft.SharePoint.Linq Namespace