Export (0) Print
Expand All

EntityRef<TEntity> Class

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

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

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

[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.

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.

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.

}

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